]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-find-lang
- use if statement to increase readability
[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 usage () {
36 cat <<EOF
37
38 Usage: $0 TOP_DIR PACKAGE_NAME [prefix]
39
40 where TOP_DIR is
41 the top of the tree containing the files to be processed--should be
42 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
43 PACKAGE_NAME is the %{name} of the package. This should also be
44 the basename of the .mo files.  the output is written to
45 PACKAGE_NAME.lang unless \$3 is given in which case output is written
46 to \$3.
47 Additional options:
48   --with-gnome          find GNOME help files
49   --with-kde            find KDE help files
50   --all-name            match all package/domain names
51   --without-mo          skip *.mo locale files
52 EOF
53 exit 1
54 }
55
56 if [ -z "$1" ]; then
57         usage
58 elif [ $1 = / ]; then
59         echo >&2 "$0: expects non-/ argument for '$1'"
60 elif [ ! -d $1 ]; then
61         echo "$0: $1: no such directory"
62         exit 1
63 else
64         TOP_DIR="${1%/}"
65 fi
66 shift
67
68 if [ -z "$1" ]; then
69         usage
70 else
71         NAME=$1
72 fi
73 shift
74
75 GNOME='#'
76 KDE='#'
77 MO=''
78 MO_NAME=$NAME.lang
79 ALL_NAME='#'
80 NO_ALL_NAME=''
81 while test $# -gt 0 ; do
82     case "$1" in
83         --with-gnome)
84                 GNOME=''
85                 shift
86                 ;;
87         --with-kde)
88                 KDE=''
89                 shift
90                 ;;
91         --without-mo)
92                 MO='#'
93                 shift
94                 ;;
95         --all-name)
96                 ALL_NAME=''
97                 NO_ALL_NAME='#'
98                 shift
99                 ;;
100         * )
101                 MO_NAME=$1
102                 shift
103                 ;;
104     esac
105 done    
106
107 echo '%defattr(644,root,root,755)' > $MO_NAME
108
109 if [ ! -f __find.files ]; then
110         find $TOP_DIR -type f -name '*.mo' | xargs -r file | egrep -v ', 1 messages$' | \
111         sed -e '
112                 s/:.*//
113                 s:'"$TOP_DIR"'::' > __find.files
114 fi
115
116 (
117         if [ "$ALL_NAME" ]; then
118                 fgrep $NAME __find.files
119         else
120                 cat __find.files
121         fi
122 ) | sed '
123 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
124 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
125 s:^\([^%].*\)::
126 s:%lang(C) ::
127 s:^\$::' | egrep -v '^$' >> $MO_NAME
128
129 if [ ! -f __find.dirs ]; then
130         find $TOP_DIR -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
131 fi
132
133 (
134         if [ "$ALL_NAME" ]; then
135                 fgrep $NAME __find.dirs
136         else
137                 cat __find.dirs
138         fi
139 ) | sed '
140 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
141 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
142 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/]\+\):%lang(\2) \1\2:
143 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
144 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
145 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/]\+\):%lang(\2) \1\2:
146 s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
147 s:^\([^%].*\)::
148 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
149
150 { [ "$ALL_NAME" ] || cat __find.dirs && fgrep $NAME __find.dirs; } | sed '
151 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
152 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
153 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
154 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
155 s:^\([^%].*\)::
156 s:%lang(C) ::' | egrep -v '^$' >> $MO_NAME
157
158 if [ "$(egrep -v '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
159         echo 'Error: international files not found !'
160         exit 1
161 fi
This page took 0.050925 seconds and 4 git commands to generate.