2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright (C) 1998-2018 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 BUGURL
="https://gcc.gnu.org/bugs/"
26 # Always operate in the C locale.
30 export LANG LANGUAGE LC_ALL
32 # Set AWK if environment has not already set it.
35 # The arguments to this wrapper are: the program to execute, the
36 # name of the "package", and the path to the source directory.
39 then echo "usage: $0 <xgettext> <package> <srcdir>"
47 case `$xgettext --version | sed -e 1q | sed -e 's/^\([^0-9]*\)//'` in
48 0.14.
[5-9]* |
0.14.
[1-9][0-9]* |
0.1[5-9]* |
0.
[2-9][0-9]* |
[1-9].
*) : ;;
49 *) echo "$xgettext is too old. GNU xgettext 0.14.5 is required"
58 # Create temporary directory for scratch files.
64 kopt
=$pwd/$T/keyword-options
65 kopt2
=$pwd/$T/keyword2-options
66 emsg
=$pwd/$T/emsgids.c
67 posr
=$pwd/$T/po-sources
68 posrcxx
=$pwd/$T/po-cxx-sources
69 pottmp1
=$pwd/$T/tmp1.pot
70 pottmp2
=$pwd/$T/tmp2.pot
71 pottmp3
=$pwd/$T/tmp3.pot
72 pottmp
=$pwd/$T/tmp.pot
74 # Locate files to scan. We scan the following directories:
78 # $srcdir/common/config
79 # $srcdir/common/config/*
82 # all subdirectories of $srcdir containing a config-lang.in file, and
83 # all subdirectories of those directories.
84 # Within those directories, we examine all .c, .cc, .h, and .def files.
85 # However, any files listed in $srcdir/po/EXCLUDE are not examined.
87 # Then generate keyword options for xgettext, by scanning for declarations
88 # of functions whose parameter names end in "msgid".
90 # Finally, generate a source file containing all %e and %n strings from
91 # driver specs, so those can be translated too.
93 # All in one huge awk script.
95 echo "scanning for keywords, %e and %n strings..." >&2
98 lang_subdirs
=`echo */config-lang.in */*/config-lang.in | sed -e 's|/config-lang\.in||g'`
99 { for dir
in "" c-family
/ common
/ common
/config
/ common
/config
/*/ \
101 `find $lang_subdirs -type d -print | fgrep -v .svn | sort | sed -e 's|$|/|'`
102 do for glob
in '*.c' '*.cc' '*.h' '*.def'
103 do eval echo $dir$glob
106 } |
tr ' ' "$nl" |
grep -v '\*' |
107 $AWK -v excl
=po
/EXCLUDES
-v posr
=$posr -v posrcxx
=$posrcxx -v kopt
=$kopt -v kopt2
=$kopt2 -v emsg
=$emsg '
108 function keyword_option(line) {
109 paren_index = index(line, "(")
110 name = substr(line, 1, paren_index - 1)
111 sub(/[^0-9A-Z_a-z]*$/, "", name)
112 sub(/[ ]+PARAMS/, "", name)
113 sub(/[ ]+VPARAMS/, "", name)
114 sub(/.*[^0-9A-Z_a-z]/, "", name)
116 args = substr(line, paren_index)
117 sub(/msgid[,\)].*/, "", args)
118 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
123 format="gcc-internal-format"
124 else if (args ~ /noc$/)
126 else if (args ~ /c$/)
129 if (n == 1) { keyword = "--keyword=" name }
131 keyword = "--keyword=" name ":" n
133 keyword = keyword "," (n + 1)
136 keyword=keyword "\n--flag=" name ":" n ":" format
138 keyword = keyword "\n--flag=" name ":" (n + 1) ":" format
141 if (! keyword_seen[name]) {
142 if (format == "gcc-internal-format")
143 print keyword > kopt2
146 keyword_seen[name] = keyword
147 } else if (keyword_seen[name] != keyword) {
148 printf("%s used incompatibly as both %s and %s\n",
149 name, keyword_seen[name], keyword)
154 function spec_error_string (line) {
155 if (index(line, "%e") != 0 && index(line, "%n") != 0) return
156 while ((percent_index = index(line, "%e")) != 0 ||
157 (percent_index = index(line, "%n")) != 0) {
158 line = substr(line, percent_index + 2)
160 bracket_index = index(line, "}")
161 newline_index = index(line, "\\n")
163 quote_index = index(line, "\"")
164 if (bracket_index == 0 && newline_index == 0) return
166 if (bracket_index != 0) {
167 if (quote_index != 0 && bracket_index > quote_index) return
168 msgid = substr(line, 1, bracket_index - 1)
169 line = substr(line, bracket_index + 1)
171 else if (newline_index != 0) {
172 if (quote_index != 0 && quote_index > newline_index) return
173 msgid = substr(line, 1, newline_index - 1)
174 line = substr(line, newline_index + 1)
177 if (index(msgid, "%") != 0) continue
179 if ((newline_index = index(msgid, "\\n")) != 0)
180 msgid = substr(msgid, 1, newline_index - 1)
181 printf("#line %d \"%s\"\n", lineno, file) > emsg
182 printf("_(\"%s\")\n", msgid) > emsg
187 while ((getline < excl) > 0) {
188 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
194 { if (!($0 in excludes)) {
208 while (getline < file) {
209 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
211 } else if (/^(#[ ]*define[ ]*)?[A-Za-z_].*(\(|\(.*,)$/) {
213 while (getline < file) {
216 keyword_option(name_line $0)
219 name_line = name_line $0
223 } else if (/%e/ || /%n/) {
224 spec_error_string($0)
233 echo "scanning option files..." >&2
235 ( cd $srcdir; find .
-name '*.opt' -print |
240 while (getline < file) {
241 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
243 printf("_(\"%s\")\n", line)
246 if ((field == 1) && /MissingArgError/) {
248 sub(".*MissingArgError\\(", "", line)
251 sub("}\\).*", "", line)
253 sub("\\).*", "", line)
254 printf("#line %d \"%s\"\n", lineno, file)
255 printf("_(\"%s\")\n", line)
257 if ((field == 1) && /UnknownError/) {
259 sub(".*UnknownError\\(", "", line)
262 sub("}\\).*", "", line)
264 sub("\\).*", "", line)
265 printf("#line %d \"%s\"\n", lineno, file)
266 printf("_(\"%s\")\n", line)
268 if ((field == 1) && /Warn\(/) {
270 sub(".*Warn\\(", "", line)
273 sub("}\\).*", "", line)
275 sub("\\).*", "", line)
276 printf("#line %d \"%s\"\n", lineno, file)
277 printf("_(\"%s\")\n", line)
281 printf("#line %d \"%s\"\n", lineno, file)
282 } else if (field > 2) {
290 printf("_(\"%s\")\n", line)
293 # Run the xgettext commands, with temporary added as a file to scan.
294 echo "running xgettext..." >&2
295 $xgettext --default-domain=$package --directory=$srcdir \
296 --add-comments `cat $kopt` --files-from=$posr \
297 --copyright-holder="Free Software Foundation, Inc." \
298 --msgid-bugs-address="$BUGURL" \
299 --language=c
-o $pottmp1
300 if test -s $posrcxx; then
301 $xgettext --default-domain=$package --directory=$srcdir \
302 --add-comments `cat $kopt` --files-from=$posrcxx \
303 --copyright-holder="Free Software Foundation, Inc." \
304 --msgid-bugs-address="$BUGURL" \
305 --language=c
++ -o $pottmp2
309 $xgettext --default-domain=$package --directory=$srcdir \
310 --add-comments --keyword= `cat $kopt2` --files-from=$posr \
311 --copyright-holder="Free Software Foundation, Inc." \
312 --msgid-bugs-address="$BUGURL" \
313 --language=GCC-source
-o $pottmp3
314 $xgettext --default-domain=$package \
315 --add-comments $pottmp1 $pottmp2 $pottmp3 \
316 --copyright-holder="Free Software Foundation, Inc." \
317 --msgid-bugs-address="$BUGURL" \
318 --language=PO
-o $pottmp
319 # Remove local paths from .pot file.
320 sed "s:$srcdir/::g;s:$pwd/::g;" <$pottmp >po
/$package.pot