2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright 1998, 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
5 # Written by Paul Eggert <eggert@twinsun.com>.
6 # Revised by Zack Weinberg <zackw@stanford.edu> for no-POTFILES operation.
8 # This file is part of GCC.
10 # GCC is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3, or (at your option)
15 # GCC is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with GCC; see the file COPYING3. If not see
22 # <http://www.gnu.org/licenses/>.
24 # Always operate in the C locale.
28 export LANG LANGUAGE LC_ALL
30 # Set AWK if environment has not already set it.
33 # The arguments to this wrapper are: the program to execute, the
34 # name of the "package", and the path to the source directory.
37 then echo "usage: $0 <xgettext> <package> <srcdir>"
45 case `$xgettext --version | sed -e 1q | sed -e 's/^\([^0-9]*\)//'` in
46 0.14.
[5-9]* |
0.14.
[1-9][0-9]* |
0.1[5-9]* |
0.
[2-9][0-9]* |
[1-9].
*) : ;;
47 *) echo "$xgettext is too old. GNU xgettext 0.14.5 is required"
56 # Create temporary directory for scratch files.
62 kopt
=$pwd/$T/keyword-options
63 kopt2
=$pwd/$T/keyword2-options
64 emsg
=$pwd/$T/emsgids.c
65 posr
=$pwd/$T/po-sources
66 posrcxx
=$pwd/$T/po-cxx-sources
67 pottmp1
=$pwd/$T/tmp1.pot
68 pottmp2
=$pwd/$T/tmp2.pot
69 pottmp3
=$pwd/$T/tmp3.pot
70 pottmp
=$pwd/$T/tmp.pot
72 # Locate files to scan. We scan the following directories:
77 # all subdirectories of $srcdir containing a config-lang.in file, and
78 # all subdirectories of those directories.
79 # Within those directories, we examine all .c, .cc, .h, and .def files.
80 # However, any files listed in $srcdir/po/EXCLUDE are not examined.
82 # Then generate keyword options for xgettext, by scanning for declarations
83 # of functions whose parameter names end in "msgid".
85 # Finally, generate a source file containing all %e and %n strings from
86 # driver specs, so those can be translated too.
88 # All in one huge awk script.
90 echo "scanning for keywords, %e and %n strings..." >&2
93 lang_subdirs
=`echo */config-lang.in */*/config-lang.in | sed -e 's|/config-lang\.in||g'`
94 { for dir
in "" c-family
/ config
/ config
/*/ \
95 `find $lang_subdirs -type d -print | fgrep -v .svn | sort | sed -e 's|$|/|'`
96 do for glob
in '*.c' '*.cc' '*.h' '*.def'
97 do eval echo $dir$glob
100 } |
tr ' ' "$nl" |
grep -v '\*' |
101 $AWK -v excl
=po
/EXCLUDES
-v posr
=$posr -v posrcxx
=$posrcxx -v kopt
=$kopt -v kopt2
=$kopt2 -v emsg
=$emsg '
102 function keyword_option(line) {
103 paren_index = index(line, "(")
104 name = substr(line, 1, paren_index - 1)
105 sub(/[^0-9A-Z_a-z]*$/, "", name)
106 sub(/[ ]+PARAMS/, "", name)
107 sub(/[ ]+VPARAMS/, "", name)
108 sub(/.*[^0-9A-Z_a-z]/, "", name)
110 args = substr(line, paren_index)
111 sub(/msgid[,\)].*/, "", args)
112 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
117 format="gcc-internal-format"
118 else if (args ~ /noc$/)
120 else if (args ~ /c$/)
123 if (n == 1) { keyword = "--keyword=" name }
125 keyword = "--keyword=" name ":" n
127 keyword = keyword "," (n + 1)
130 keyword=keyword "\n--flag=" name ":" n ":" format
132 keyword = keyword "\n--flag=" name ":" (n + 1) ":" format
135 if (! keyword_seen[name]) {
136 if (format == "gcc-internal-format")
137 print keyword > kopt2
140 keyword_seen[name] = keyword
141 } else if (keyword_seen[name] != keyword) {
142 printf("%s used incompatibly as both %s and %s\n",
143 name, keyword_seen[name], keyword)
148 function spec_error_string (line) {
149 if (index(line, "%e") != 0 && index(line, "%n") != 0) return
150 while ((percent_index = index(line, "%e")) != 0 ||
151 (percent_index = index(line, "%n")) != 0) {
152 line = substr(line, percent_index + 2)
154 bracket_index = index(line, "}")
155 newline_index = index(line, "\\n")
157 quote_index = index(line, "\"")
158 if (bracket_index == 0 && newline_index == 0) return
160 if (bracket_index != 0) {
161 if (quote_index != 0 && bracket_index > quote_index) return
162 msgid = substr(line, 1, bracket_index - 1)
163 line = substr(line, bracket_index + 1)
165 else if (newline_index != 0) {
166 if (quote_index != 0 && quote_index > newline_index) return
167 msgid = substr(line, 1, newline_index - 1)
168 line = substr(line, newline_index + 1)
171 if (index(msgid, "%") != 0) continue
173 if ((newline_index = index(msgid, "\\n")) != 0)
174 msgid = substr(msgid, 1, newline_index - 1)
175 printf("#line %d \"%s\"\n", lineno, file) > emsg
176 printf("_(\"%s\")\n", msgid) > emsg
181 while ((getline < excl) > 0) {
182 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
188 { if (!($0 in excludes)) {
202 while (getline < file) {
203 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
205 } else if (/^(#[ ]*define[ ]*)?[A-Za-z_].*(\(|\(.*,)$/) {
207 while (getline < file) {
210 keyword_option(name_line $0)
213 name_line = name_line $0
217 } else if (/%e/ || /%n/) {
218 spec_error_string($0)
227 echo "scanning option files..." >&2
229 ( cd $srcdir; find .
-name '*.opt' -print |
234 while (getline < file) {
235 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
238 if ((field == 1) && /MissingArgError/) {
240 sub(".*MissingArgError\\(", "", line)
243 sub("}\\).*", "", line)
245 sub("\\).*", "", line)
246 printf("#line %d \"%s\"\n", lineno, file)
247 printf("_(\"%s\")\n", line)
249 if ((field == 1) && /UnknownError/) {
251 sub(".*UnknownError\\(", "", line)
254 sub("}\\).*", "", line)
256 sub("\\).*", "", line)
257 printf("#line %d \"%s\"\n", lineno, file)
258 printf("_(\"%s\")\n", line)
260 if ((field == 1) && /Warn\(/) {
262 sub(".*Warn\\(", "", line)
265 sub("}\\).*", "", line)
267 sub("\\).*", "", line)
268 printf("#line %d \"%s\"\n", lineno, file)
269 printf("_(\"%s\")\n", line)
273 printf("#line %d \"%s\"\n", lineno, file)
274 printf("_(\"%s\")\n", line)
282 # Run the xgettext commands, with temporary added as a file to scan.
283 echo "running xgettext..." >&2
284 $xgettext --default-domain=$package --directory=$srcdir \
285 --add-comments `cat $kopt` --files-from=$posr \
286 --copyright-holder="Free Software Foundation, Inc." \
287 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
288 --language=c
-o $pottmp1
289 if test -s $posrcxx; then
290 $xgettext --default-domain=$package --directory=$srcdir \
291 --add-comments `cat $kopt` --files-from=$posrcxx \
292 --copyright-holder="Free Software Foundation, Inc." \
293 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
294 --language=c
++ -o $pottmp2
298 $xgettext --default-domain=$package --directory=$srcdir \
299 --add-comments --keyword= `cat $kopt2` --files-from=$posr \
300 --copyright-holder="Free Software Foundation, Inc." \
301 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
302 --language=GCC-source
-o $pottmp3
303 $xgettext --default-domain=$package \
304 --add-comments $pottmp1 $pottmp2 $pottmp3 \
305 --copyright-holder="Free Software Foundation, Inc." \
306 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
307 --language=PO
-o $pottmp
308 # Remove local paths from .pot file.
309 sed "s:$srcdir/::g;s:$pwd/::g;" <$pottmp >po
/$package.pot