Avoid noise from python bytecompile on non-python pkgs (RhBug:539635)
[platform/upstream/rpm.git] / scripts / find-lang.sh
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 # 2004-06-20 Arkadiusz Miƛkiewicz <arekm@pld-linux.org>
15 #   * merge PLD changes, kde, all-name (mkochano,pascalek@PLD)
16 # 1999-10-19 Artur Frysiak <wiget@pld-linux.org>
17 #   * added support for GNOME help files
18 #   * start support for KDE help files
19
20 usage () {
21 cat <<EOF
22
23 Usage: $0 TOP_DIR PACKAGE_NAME [prefix]
24
25 where TOP_DIR is
26 the top of the tree containing the files to be processed--should be
27 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
28 PACKAGE_NAME is the %{name} of the package. This should also be
29 the basename of the .mo files.  the output is written to
30 PACKAGE_NAME.lang unless \$3 is given in which case output is written
31 to \$3.
32 Additional options:
33   --with-gnome          find GNOME help files
34   --with-kde            find KDE help files
35   --with-qt             find Qt translation files
36   --with-man            find localized man pages
37   --all-name            match all package/domain names
38   --without-mo          do not find locale files
39 EOF
40 exit 1
41 }
42
43 if [ -z "$1" ] ; then usage
44 elif [ $1 = / ] ; then echo $0: expects non-/ argument for '$1' 1>&2
45 elif [ ! -d $1 ] ; then
46  echo $0: $1: no such directory
47  exit 1
48 else TOP_DIR="`echo $1|sed -e 's:/$::'`"
49 fi
50 shift
51
52 if [ -z "$1" ] ; then usage
53 else NAME=$1
54 fi
55 shift
56
57 GNOME=#
58 KDE=#
59 QT=#
60 MAN=#
61 MO=
62 MO_NAME=$NAME.lang
63 ALL_NAME=#
64 NO_ALL_NAME=
65
66 while test $# -gt 0 ; do
67     case "${1}" in
68         --with-gnome )
69                 GNOME=
70                 shift
71                 ;;
72         --with-kde )
73                 KDE=
74                 shift
75                 ;;
76         --with-qt )
77                 QT=
78                 shift
79                 ;;
80         --with-man )
81                 MAN=
82                 shift
83                 ;;
84         --without-mo )
85                 MO=#
86                 shift
87                 ;;
88         --all-name )
89                 ALL_NAME=
90                 NO_ALL_NAME=#
91                 shift
92                 ;;
93         * )
94                 MO_NAME=${1}
95                 shift
96                 ;;
97     esac
98 done    
99
100 find $TOP_DIR -type f -o -type l|sed '
101 s:'"$TOP_DIR"'::
102 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*\.mo$\):%lang(\2) \1\2\3:
103 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/_]\+\)\(.*/'"$NAME"'\.mo$\):%lang(\2) \1\2\3:
104 s:^\([^%].*\)::
105 s:%lang(C) ::
106 /^$/d' > $MO_NAME
107
108 find $TOP_DIR -type d|sed '
109 s:'"$TOP_DIR"'::
110 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
111 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/[a-zA-Z0-9.\_\-]/.\+\)::
112 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'\/\)\([^/_]\+\):%lang(\2) \1\2:
113 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
114 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]/.\+\)::
115 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[a-zA-Z0-9.\_\-]\+\/\)\([^/_]\+\):%lang(\2) \1\2:
116 s:%lang(.*) .*/gnome/help/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+/.*::
117 s:^\([^%].*\)::
118 s:%lang(C) ::
119 /^$/d' >> $MO_NAME
120
121 find $TOP_DIR -type d|sed '
122 s:'"$TOP_DIR"'::
123 '"$NO_ALL_NAME$GNOME"'s:\(.*/omf/'"$NAME"'$\):%dir \1:
124 '"$ALL_NAME$GNOME"'s:\(.*/omf/[a-zA-Z0-9.\_\-]\+$\):%dir \1:
125 s:^\([^%].*\)::
126 /^$/d' >> $MO_NAME
127
128 find $TOP_DIR -type f|sed '
129 s:'"$TOP_DIR"'::
130 '"$NO_ALL_NAME$GNOME"'s:\(.*/omf/'"$NAME"'/'"$NAME"'-\([^/.]\+\)\.omf\):%lang(\2) \1:
131 '"$ALL_NAME$GNOME"'s:\(.*/omf/[a-zA-Z0-9.\_\-]\+/[a-zA-Z0-9.\_\-]\+-\([^/.]\+\)\.omf\):%lang(\2) \1:
132 s:^[^%].*::
133 s:%lang(C) ::
134 /^$/d' >> $MO_NAME
135
136 KDE3_HTML=`kde-config --expandvars --install html 2>/dev/null`
137 if [ x"$KDE3_HTML" != x -a -d "$TOP_DIR$KDE3_HTML" ]; then
138 find $TOP_DIR$KDE3_HTML -type d|sed '
139 s:'"$TOP_DIR"'::
140 '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
141 '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
142 '"$ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
143 '"$ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
144 s:^\([^%].*\)::
145 s:%lang(C) ::
146 /^$/d' >> $MO_NAME
147 fi
148
149 KDE4_HTML=`kde4-config --expandvars --install html 2>/dev/null`
150 if [ x"$KDE4_HTML" != x -a -d "$TOP_DIR$KDE4_HTML" ]; then
151 find $TOP_DIR$KDE4_HTML -type d|sed '
152 s:'"$TOP_DIR"'::
153 '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'/\)::
154 '"$NO_ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/'"$NAME"'\)$:%lang(\2) \1\2\3:
155 '"$ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+/\)::
156 '"$ALL_NAME$KDE"'s:\(.*/HTML/\)\([^/_]\+\)\(.*/[a-zA-Z0-9.\_\-]\+$\):%lang(\2) \1\2\3:
157 s:^\([^%].*\)::
158 s:%lang(C) ::
159 /^$/d' >> $MO_NAME
160 fi
161
162 find $TOP_DIR -type f -o -type l|sed '
163 s:'"$TOP_DIR"'::
164 '"$NO_ALL_NAME$QT"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\(_[a-zA-Z]\{2\}\)\?\)\.qm$\):%lang(\2) \1:
165 '"$ALL_NAME$QT"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}_[a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
166 '"$ALL_NAME$QT"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
167 '"$ALL_NAME$QT"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}_[a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
168 '"$ALL_NAME$QT"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
169 s:^[^%].*::
170 s:%lang(C) ::
171 /^$/d' >> $MO_NAME
172
173 find $TOP_DIR -type d|sed '
174 s:'"$TOP_DIR"'::
175 '"$ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+/\)::
176 '"$ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+$\):%lang(\2) \1*:
177 s:^\([^%].*\)::
178 s:%lang(C) ::
179 /^$/d' >> $MO_NAME
180
181 find $TOP_DIR -type f -o -type l|sed '
182 s:'"$TOP_DIR"'::
183 '"$NO_ALL_NAME$MAN"'s:\(.*/man/\([^/_]\+\).*/man[a-z0-9]\+/'"$NAME"'\.[a-z0-9].*\):%lang(\2) \1*:
184 s:^\([^%].*\)::
185 s:%lang(C) ::
186 /^$/d' >> $MO_NAME
187
188 if ! grep -q / $MO_NAME; then
189         echo "No translations found for ${NAME} in ${TOP_DIR}"
190         exit 1
191 fi
192 exit 0