]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-find-lang
- 10000x performance boost for packages calling %find_lang more than once (try kdemod...
[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-09 Elan Ruusamäe <glen@pld-linux.org>
17 #   * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
18 # 2001-01-08 Micha³ Kochanowicz <mkochano@pld.org.pl>
19 #   * --all-name support for KDE.
20 # 2000-11-28 Rafa³ Cygnarowski <pascalek@pld.org.pl>
21 #   * next simple rule for KDE
22 # 2000-11-12 Rafa³ Cygnarowski <pascalek@pld.org.pl>
23 #   * simple rules for KDE help files
24 # 2000-06-05 Micha³ Kochanowicz <mkochano@pld.org.pl>
25 #   * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
26 #     no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
27 # 2000-04-17 Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
28 #   * exit 1 when no files found
29 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
30 #   * added support for GNOME help files
31 #   * start support for KDE help files
32
33 usage () {
34 cat <<EOF
35
36 Usage: $0 TOP_DIR PACKAGE_NAME [prefix]
37
38 where TOP_DIR is
39 the top of the tree containing the files to be processed--should be
40 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
41 PACKAGE_NAME is the %{name} of the package. This should also be
42 the basename of the .mo files.  the output is written to
43 PACKAGE_NAME.lang unless \$3 is given in which case output is written
44 to \$3.
45 Additional options:
46   --with-gnome          find GNOME help files
47   --with-kde            find KDE help files
48   --all-name            match all package/domain names
49   --without-mo          skip *.mo locale files
50 EOF
51 exit 1
52 }
53
54 if [ -z "$1" ]; then
55         usage
56 elif [ $1 = / ]; then
57         echo >&2 "$0: expects non-/ argument for '$1'"
58 elif [ ! -d $1 ]; then
59         echo "$0: $1: no such directory"
60         exit 1
61 else
62         TOP_DIR="${1%/}"
63 fi
64 shift
65
66 if [ -z "$1" ]; then
67         usage
68 else
69         NAME=$1
70 fi
71 shift
72
73 GNOME='#'
74 KDE='#'
75 MO=''
76 MO_NAME=$NAME.lang
77 ALL_NAME='#'
78 NO_ALL_NAME=''
79 while test $# -gt 0 ; do
80     case "$1" in
81         --with-gnome)
82                 GNOME=''
83                 shift
84                 ;;
85         --with-kde)
86                 KDE=''
87                 shift
88                 ;;
89         --without-mo)
90                 MO='#'
91                 shift
92                 ;;
93         --all-name)
94                 ALL_NAME=''
95                 NO_ALL_NAME='#'
96                 shift
97                 ;;
98         * )
99                 MO_NAME=$1
100                 shift
101                 ;;
102     esac
103 done    
104
105 echo '%defattr(644,root,root,755)' > $MO_NAME
106
107 if [ ! -f __find.files ]; then
108         find $TOP_DIR -type f -name '*.mo' | xargs -r file | egrep -v ', 1 messages$' | \
109         sed -e '
110                 s/:.*//
111                 s:'"$TOP_DIR"'::' > __find.files
112 fi
113
114 fgrep $NAME __find.files | sed '
115 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
116 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
117 s:^\([^%].*\)::
118 s:%lang(C) ::
119 s:^\$::' | egrep -v '^$' >> $MO_NAME
120
121 if [ ! -f __find.dirs ]; then
122         find $TOP_DIR -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
123 fi
124 fgrep $NAME __find.dirs | sed '
125 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
126 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
127 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/]\+\):%lang(\2) \1\2:
128 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
129 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
130 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/]\+\):%lang(\2) \1\2:
131 s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
132 s:^\([^%].*\)::
133 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
134
135 fgrep $NAME __find.dirs | sed '
136 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
137 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
138 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
139 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
140 s:^\([^%].*\)::
141 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
142
143 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
144         echo 'Error: international files not found !'
145         exit 1
146 fi
This page took 0.034517 seconds and 4 git commands to generate.