2 # Wrapper around gettext for programs using the msgid convention.
3 # Copyright (C) 1998-2023 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 pottmp4
=$pwd/$T/tmp4.pot
73 pottmp
=$pwd/$T/tmp.pot
75 # Locate files to scan. We scan the following directories:
79 # $srcdir/common/config
80 # $srcdir/common/config/*
83 # all subdirectories of $srcdir containing a config-lang.in file, and
84 # all subdirectories of those directories.
85 # Within those directories, we examine all .c, .cc, .h, and .def files.
86 # However, any files listed in $srcdir/po/EXCLUDE are not examined.
88 # Then generate keyword options for xgettext, by scanning for declarations
89 # of functions whose parameter names end in "msgid".
91 # Finally, generate a source file containing all %e and %n strings from
92 # driver specs, so those can be translated too.
94 # All in one huge awk script.
96 echo "scanning for keywords, %e and %n strings..." >&2
99 lang_subdirs
=`echo */config-lang.in */*/config-lang.in | sed -e 's|/config-lang\.in||g'`
100 { for dir
in "" c-family
/ common
/ common
/config
/ common
/config
/*/ \
102 `find $lang_subdirs -type d -print | sort | sed -e 's|$|/|'`
103 do for glob
in '*.c' '*.cc' '*.h' '*.def'
104 do eval echo $dir$glob
107 } |
tr ' ' "$nl" |
grep -v '\*' |
108 $AWK -v excl
=po
/EXCLUDES
-v posr
=$posr -v posrcxx
=$posrcxx -v kopt
=$kopt -v kopt2
=$kopt2 -v emsg
=$emsg '
109 function keyword_option(line) {
110 paren_index = index(line, "(")
111 name = substr(line, 1, paren_index - 1)
112 sub(/[^0-9A-Z_a-z]*$/, "", name)
113 sub(/[ ]+PARAMS/, "", name)
114 sub(/[ ]+VPARAMS/, "", name)
115 sub(/.*[^0-9A-Z_a-z]/, "", name)
117 args = substr(line, paren_index)
118 sub(/msgid[,\)].*/, "", args)
119 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
124 format="gcc-internal-format"
125 else if (args ~ /noc$/)
127 else if (args ~ /c$/)
130 if (n == 1) { keyword = "--keyword=" name }
132 keyword = "--keyword=" name ":" n
134 keyword = keyword "," (n + 1)
137 keyword=keyword "\n--flag=" name ":" n ":" format
139 keyword = keyword "\n--flag=" name ":" (n + 1) ":" format
142 if (! keyword_seen[name]) {
143 if (format == "gcc-internal-format")
144 print keyword > kopt2
147 keyword_seen[name] = keyword
148 } else if (keyword_seen[name] != keyword) {
149 printf("%s used incompatibly as both %s and %s\n",
150 name, keyword_seen[name], keyword)
155 function spec_error_string (line) {
156 if (index(line, "%e") != 0 && index(line, "%n") != 0) return
157 while ((percent_index = index(line, "%e")) != 0 ||
158 (percent_index = index(line, "%n")) != 0) {
159 line = substr(line, percent_index + 2)
161 bracket_index = index(line, "}")
162 newline_index = index(line, "\\n")
164 quote_index = index(line, "\"")
165 if (bracket_index == 0 && newline_index == 0) return
167 if (bracket_index != 0) {
168 if (quote_index != 0 && bracket_index > quote_index) return
169 msgid = substr(line, 1, bracket_index - 1)
170 line = substr(line, bracket_index + 1)
172 else if (newline_index != 0) {
173 if (quote_index != 0 && quote_index > newline_index) return
174 msgid = substr(line, 1, newline_index - 1)
175 line = substr(line, newline_index + 1)
178 if (index(msgid, "%") != 0) continue
180 if ((newline_index = index(msgid, "\\n")) != 0)
181 msgid = substr(msgid, 1, newline_index - 1)
182 printf("#line %d \"%s\"\n", lineno, file) > emsg
183 printf("_(\"%s\")\n", msgid) > emsg
188 while ((getline < excl) > 0) {
189 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
195 { if (!($0 in excludes)) {
209 while (getline < file) {
210 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
212 } else if (/^(#[ ]*define[ ]*)?[A-Za-z_].*(\(|\(.*,)$/) {
214 while (getline < file) {
217 keyword_option(name_line $0)
220 name_line = name_line $0
224 } else if (/%e/ || /%n/) {
225 spec_error_string($0)
231 print "--keyword=__opt_help_text\n--flag=__opt_help_text:1:no-c-format" >> kopt
235 echo "scanning option files..." >&2
237 ( cd $srcdir; find .
-name '*.opt' -print |
242 while (getline < file) {
243 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
245 printf("__opt_help_text(\"%s\")\n", line)
248 if ((field == 1) && /MissingArgError/) {
250 sub(".*MissingArgError\\(", "", line)
253 sub("}\\).*", "", line)
255 sub("\\).*", "", line)
256 printf("#line %d \"%s\"\n", lineno, file)
257 printf("error(\"%s\")\n", line)
259 if ((field == 1) && /UnknownError/) {
261 sub(".*UnknownError\\(", "", line)
264 sub("}\\).*", "", line)
266 sub("\\).*", "", line)
267 printf("#line %d \"%s\"\n", lineno, file)
268 printf("error(\"%s\")\n", line)
270 if ((field == 1) && /Warn\(/) {
272 sub(".*Warn\\(", "", line)
275 sub("}\\).*", "", line)
277 sub("\\).*", "", line)
278 printf("#line %d \"%s\"\n", lineno, file)
279 printf("warning(0, \"%s\")\n", line)
283 printf("#line %d \"%s\"\n", lineno, file)
284 } else if (field > 2) {
292 printf("__opt_help_text(\"%s\")\n", line)
295 # Run the xgettext commands, with temporary added as a file to scan.
296 echo "running xgettext..." >&2
297 $xgettext --default-domain=$package --directory=$srcdir \
298 --add-comments `cat $kopt` --files-from=$posr \
299 --copyright-holder="Free Software Foundation, Inc." \
300 --msgid-bugs-address="$BUGURL" \
301 --language=c
-o $pottmp1
302 if test -s $posrcxx; then
303 $xgettext --default-domain=$package --directory=$srcdir \
304 --add-comments `cat $kopt` --files-from=$posrcxx \
305 --copyright-holder="Free Software Foundation, Inc." \
306 --msgid-bugs-address="$BUGURL" \
307 --language=c
++ -o $pottmp2
311 $xgettext --default-domain=$package --directory=$srcdir \
312 --add-comments --keyword= `cat $kopt2` --files-from=$posr \
313 --copyright-holder="Free Software Foundation, Inc." \
314 --msgid-bugs-address="$BUGURL" \
315 --language=GCC-source
-o $pottmp3
316 $xgettext --default-domain=$package --directory=$srcdir \
317 --add-comments --keyword= `cat $kopt2` --files-from=$posrcxx \
318 --copyright-holder="Free Software Foundation, Inc." \
319 --msgid-bugs-address="$BUGURL" \
320 --language=GCC-source
-o $pottmp4
321 $xgettext --default-domain=$package \
322 --add-comments $pottmp1 $pottmp2 $pottmp3 $pottmp4 \
323 --copyright-holder="Free Software Foundation, Inc." \
324 --msgid-bugs-address="$BUGURL" \
325 --language=PO
-o $pottmp
326 # Remove local paths from .pot file.
327 sed "s:$srcdir/::g;s:$pwd/::g;" <$pottmp >po
/$package.pot