[AArch64] Avoid GET_MODE_NUNITS in v8.4 support
[official-gcc.git] / gcc / po / exgettext
blob71d7561d740f7b782f3a96d5c42a5cdb18ab6c61
1 #! /bin/sh
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)
13 # any later version.
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.
27 LANG=C
28 LANGUAGE=C
29 LC_ALL=C
30 export LANG LANGUAGE LC_ALL
32 # Set AWK if environment has not already set it.
33 AWK=${AWK-awk}
35 # The arguments to this wrapper are: the program to execute, the
36 # name of the "package", and the path to the source directory.
38 if [ $# -ne 3 ]
39 then echo "usage: $0 <xgettext> <package> <srcdir>"
40 exit 1
43 xgettext=$1
44 package=$2
45 srcdir=$3
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"
50 exit 1 ;;
51 esac
53 nl='
56 set -e
58 # Create temporary directory for scratch files.
59 T=exg$$.d
60 mkdir $T
61 trap "rm -r $T" 0
63 pwd=`${PWDCMD-pwd}`
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:
75 # $srcdir
76 # $srcdir/c-family
77 # $srcdir/common
78 # $srcdir/common/config
79 # $srcdir/common/config/*
80 # $srcdir/config
81 # $srcdir/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
97 ( cd $srcdir
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/*/ \
100 config/ 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
104 done
105 done;
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++) {
119 continue
121 format=""
122 if (args ~ /g$/)
123 format="gcc-internal-format"
124 else if (args ~ /noc$/)
125 format="no-c-format"
126 else if (args ~ /c$/)
127 format="c-format"
129 if (n == 1) { keyword = "--keyword=" name }
130 else {
131 keyword = "--keyword=" name ":" n
132 if (name ~ /_n$/)
133 keyword = keyword "," (n + 1)
135 if (format) {
136 keyword=keyword "\n--flag=" name ":" n ":" format
137 if (name ~ /_n$/)
138 keyword = keyword "\n--flag=" name ":" (n + 1) ":" format
141 if (! keyword_seen[name]) {
142 if (format == "gcc-internal-format")
143 print keyword > kopt2
144 else
145 print keyword > kopt
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)
150 exit (1)
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
186 BEGIN {
187 while ((getline < excl) > 0) {
188 if ($0 ~ /^#/ || $0 ~ /^[ ]*$/)
189 continue
190 excludes[$1] = 1
194 { if (!($0 in excludes)) {
195 if ($0 ~ /.cc$/) {
196 print > posrcxx
197 } else {
198 print > posr
200 files[NR] = $0
204 END {
205 for (f in files) {
206 file = files[f]
207 lineno = 1
208 while (getline < file) {
209 if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
210 keyword_option($0)
211 } else if (/^(#[ ]*define[ ]*)?[A-Za-z_].*(\(|\(.*,)$/) {
212 name_line = $0
213 while (getline < file) {
214 lineno++
215 if (/msgid[,\)]/){
216 keyword_option(name_line $0)
217 break
218 } else if (/,$/) {
219 name_line = name_line $0
220 continue
221 } else break
223 } else if (/%e/ || /%n/) {
224 spec_error_string($0)
226 lineno++
229 print emsg > posr
231 ) || exit
233 echo "scanning option files..." >&2
235 ( cd $srcdir; find . -name '*.opt' -print |
236 $AWK '{
237 file = $1
238 lineno = 1
239 field = 0
240 while (getline < file) {
241 if (/^[ \t]*(;|$)/ || !/^[^ \t]/) {
242 if (field > 2)
243 printf("_(\"%s\")\n", line)
244 field = 0
245 } else {
246 if ((field == 1) && /MissingArgError/) {
247 line = $0
248 sub(".*MissingArgError\\(", "", line)
249 if (line ~ "^{") {
250 sub("^{", "", line)
251 sub("}\\).*", "", line)
252 } else
253 sub("\\).*", "", line)
254 printf("#line %d \"%s\"\n", lineno, file)
255 printf("_(\"%s\")\n", line)
257 if ((field == 1) && /UnknownError/) {
258 line = $0
259 sub(".*UnknownError\\(", "", line)
260 if (line ~ "^{") {
261 sub("^{", "", line)
262 sub("}\\).*", "", line)
263 } else
264 sub("\\).*", "", line)
265 printf("#line %d \"%s\"\n", lineno, file)
266 printf("_(\"%s\")\n", line)
268 if ((field == 1) && /Warn\(/) {
269 line = $0
270 sub(".*Warn\\(", "", line)
271 if (line ~ "^{") {
272 sub("^{", "", line)
273 sub("}\\).*", "", line)
274 } else
275 sub("\\).*", "", line)
276 printf("#line %d \"%s\"\n", lineno, file)
277 printf("_(\"%s\")\n", line)
279 if (field == 2) {
280 line = $0
281 printf("#line %d \"%s\"\n", lineno, file)
282 } else if (field > 2) {
283 line = line " " $0
285 field++;
287 lineno++;
289 if (field > 2)
290 printf("_(\"%s\")\n", line)
291 }') >> $emsg
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
306 else
307 echo > $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