2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright (C) 1998-2014 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:
76 # $srcdir/common/config
77 # $srcdir/common/config/*
80 # all subdirectories of $srcdir containing a config-lang.in file, and
81 # all subdirectories of those directories.
82 # Within those directories, we examine all .c, .cc, .h, and .def files.
83 # However, any files listed in $srcdir/po/EXCLUDE are not examined.
85 # Then generate keyword options for xgettext, by scanning for declarations
86 # of functions whose parameter names end in "msgid".
88 # Finally, generate a source file containing all %e and %n strings from
89 # driver specs, so those can be translated too.
91 # All in one huge awk script.
93 echo "scanning for keywords, %e and %n strings..." >&2
96 lang_subdirs
=`echo */config-lang.in */*/config-lang.in | sed -e 's|/config-lang\.in||g'`
97 { for dir
in "" c-family
/ common
/ common
/config
/ common
/config
/*/ \
99 `find $lang_subdirs -type d -print | fgrep -v .svn | sort | sed -e 's|$|/|'`
100 do for glob
in '*.c' '*.cc' '*.h' '*.def'
101 do eval echo $dir$glob
104 } |
tr ' ' "$nl" |
grep -v '\*' |
105 $AWK -v excl
=po
/EXCLUDES
-v posr
=$posr -v posrcxx
=$posrcxx -v kopt
=$kopt -v kopt2
=$kopt2 -v emsg
=$emsg '
106 function keyword_option(line) {
107 paren_index = index(line, "(")
108 name = substr(line, 1, paren_index - 1)
109 sub(/[^0-9A-Z_a-z]*$/, "", name)
110 sub(/[ ]+PARAMS/, "", name)
111 sub(/[ ]+VPARAMS/, "", name)
112 sub(/.*[^0-9A-Z_a-z]/, "", name)
114 args = substr(line, paren_index)
115 sub(/msgid[,\)].*/, "", args)
116 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
121 format="gcc-internal-format"
122 else if (args ~ /noc$/)
124 else if (args ~ /c$/)
127 if (n == 1) { keyword = "--keyword=" name }
129 keyword = "--keyword=" name ":" n
131 keyword = keyword "," (n + 1)
134 keyword=keyword "\n--flag=" name ":" n ":" format
136 keyword = keyword "\n--flag=" name ":" (n + 1) ":" format
139 if (! keyword_seen[name]) {
140 if (format == "gcc-internal-format")
141 print keyword > kopt2
144 keyword_seen[name] = keyword
145 } else if (keyword_seen[name] != keyword) {
146 printf("%s used incompatibly as both %s and %s\n",
147 name, keyword_seen[name], keyword)
152 function spec_error_string (line) {
153 if (index(line, "%e") != 0 && index(line, "%n") != 0) return
154 while ((percent_index = index(line, "%e")) != 0 ||
155 (percent_index = index(line, "%n")) != 0) {
156 line = substr(line, percent_index + 2)
158 bracket_index = index(line, "}")
159 newline_index = index(line, "\\n")
161 quote_index = index(line, "\"")
162 if (bracket_index == 0 && newline_index == 0) return
164 if (bracket_index != 0) {
165 if (quote_index != 0 && bracket_index > quote_index) return
166 msgid = substr(line, 1, bracket_index - 1)
167 line = substr(line, bracket_index + 1)
169 else if (newline_index != 0) {
170 if (quote_index != 0 && quote_index > newline_index) return
171 msgid = substr(line, 1, newline_index - 1)
172 line = substr(line, newline_index + 1)
175 if (index(msgid, "%") != 0) continue
177 if ((newline_index = index(msgid, "\\n")) != 0)
178 msgid = substr(msgid, 1, newline_index - 1)
179 printf("#line %d \"%s\"\n", lineno, file) > emsg
180 printf("_(\"%s\")\n", msgid) > emsg
185 while ((getline < excl) > 0) {
186 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
192 { if (!($0 in excludes)) {
206 while (getline < file) {
207 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
209 } else if (/^(#[ ]*define[ ]*)?[A-Za-z_].*(\(|\(.*,)$/) {
211 while (getline < file) {
214 keyword_option(name_line $0)
217 name_line = name_line $0
221 } else if (/%e/ || /%n/) {
222 spec_error_string($0)
231 echo "scanning option files..." >&2
233 ( cd $srcdir; find .
-name '*.opt' -print |
238 while (getline < file) {
239 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
242 if ((field == 1) && /MissingArgError/) {
244 sub(".*MissingArgError\\(", "", line)
247 sub("}\\).*", "", line)
249 sub("\\).*", "", line)
250 printf("#line %d \"%s\"\n", lineno, file)
251 printf("_(\"%s\")\n", line)
253 if ((field == 1) && /UnknownError/) {
255 sub(".*UnknownError\\(", "", line)
258 sub("}\\).*", "", line)
260 sub("\\).*", "", line)
261 printf("#line %d \"%s\"\n", lineno, file)
262 printf("_(\"%s\")\n", line)
264 if ((field == 1) && /Warn\(/) {
266 sub(".*Warn\\(", "", line)
269 sub("}\\).*", "", line)
271 sub("\\).*", "", line)
272 printf("#line %d \"%s\"\n", lineno, file)
273 printf("_(\"%s\")\n", line)
277 printf("#line %d \"%s\"\n", lineno, file)
278 printf("_(\"%s\")\n", line)
286 # Run the xgettext commands, with temporary added as a file to scan.
287 echo "running xgettext..." >&2
288 $xgettext --default-domain=$package --directory=$srcdir \
289 --add-comments `cat $kopt` --files-from=$posr \
290 --copyright-holder="Free Software Foundation, Inc." \
291 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
292 --language=c
-o $pottmp1
293 if test -s $posrcxx; then
294 $xgettext --default-domain=$package --directory=$srcdir \
295 --add-comments `cat $kopt` --files-from=$posrcxx \
296 --copyright-holder="Free Software Foundation, Inc." \
297 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
298 --language=c
++ -o $pottmp2
302 $xgettext --default-domain=$package --directory=$srcdir \
303 --add-comments --keyword= `cat $kopt2` --files-from=$posr \
304 --copyright-holder="Free Software Foundation, Inc." \
305 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
306 --language=GCC-source
-o $pottmp3
307 $xgettext --default-domain=$package \
308 --add-comments $pottmp1 $pottmp2 $pottmp3 \
309 --copyright-holder="Free Software Foundation, Inc." \
310 --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \
311 --language=PO
-o $pottmp
312 # Remove local paths from .pot file.
313 sed "s:$srcdir/::g;s:$pwd/::g;" <$pottmp >po
/$package.pot