]>
Commit | Line | Data |
---|---|---|
5b7874aa | 1 | #! /bin/sh |
1a7b32a3 | 2 | # Wrapper around gettext for programs using the msgid convention. |
748086b7 | 3 | # Copyright 1998, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. |
5b7874aa ZW |
4 | |
5 | # Written by Paul Eggert <eggert@twinsun.com>. | |
6 | # Revised by Zack Weinberg <zackw@stanford.edu> for no-POTFILES operation. | |
7 | ||
3014d221 NN |
8 | # This file is part of GCC. |
9 | ||
4b165558 | 10 | # GCC is free software; you can redistribute it and/or modify |
5b7874aa | 11 | # it under the terms of the GNU General Public License as published by |
748086b7 | 12 | # the Free Software Foundation; either version 3, or (at your option) |
5b7874aa ZW |
13 | # any later version. |
14 | ||
4b165558 | 15 | # GCC is distributed in the hope that it will be useful, |
5b7874aa ZW |
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. | |
19 | ||
20 | # You should have received a copy of the GNU General Public License | |
748086b7 JJ |
21 | # along with GCC; see the file COPYING3. If not see |
22 | # <http://www.gnu.org/licenses/>. | |
5b7874aa | 23 | |
1a7b32a3 ZW |
24 | # Always operate in the C locale. |
25 | LANG=C | |
26 | LANGUAGE=C | |
27 | LC_ALL=C | |
28 | export LANG LANGUAGE LC_ALL | |
29 | ||
30 | # Set AWK if environment has not already set it. | |
31 | AWK=${AWK-awk} | |
5b7874aa ZW |
32 | |
33 | # The arguments to this wrapper are: the program to execute, the | |
34 | # name of the "package", and the path to the source directory. | |
35 | ||
36 | if [ $# -ne 3 ] | |
37 | then echo "usage: $0 <xgettext> <package> <srcdir>" | |
38 | exit 1 | |
39 | fi | |
40 | ||
41 | xgettext=$1 | |
42 | package=$2 | |
43 | srcdir=$3 | |
44 | ||
4b794eaf JJ |
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" | |
48 | exit 1 ;; | |
49 | esac | |
50 | ||
5b7874aa ZW |
51 | nl=' |
52 | ' | |
53 | ||
54 | set -e | |
55 | ||
56 | # Create temporary directory for scratch files. | |
57 | T=exg$$.d | |
58 | mkdir $T | |
59 | trap "rm -r $T" 0 | |
60 | ||
1e6347d8 | 61 | pwd=`${PWDCMD-pwd}` |
5b7874aa | 62 | kopt=$pwd/$T/keyword-options |
4b794eaf | 63 | kopt2=$pwd/$T/keyword2-options |
5b7874aa ZW |
64 | emsg=$pwd/$T/emsgids.c |
65 | posr=$pwd/$T/po-sources | |
4b794eaf JJ |
66 | pottmp1=$pwd/$T/tmp1.pot |
67 | pottmp2=$pwd/$T/tmp2.pot | |
68 | pottmp=$pwd/$T/tmp.pot | |
5b7874aa | 69 | |
1a7b32a3 ZW |
70 | # Locate files to scan, and generate the list. All .c, .h, and .def files |
71 | # in $srcdir are examined, likewise $srcdir/config and $srcdir/config/* | |
5b7874aa ZW |
72 | # (directories). Also, all subdirectories of $srcdir that contain a |
73 | # config-lang.in. Exclusions come from $srcdir/po/EXCLUDE. | |
74 | # | |
75 | # Then generate keyword options for xgettext, by scanning for declarations | |
76 | # of functions whose parameter names end in "msgid". | |
77 | # | |
78 | # Finally, generate a source file containing all %e strings from | |
79 | # driver specs, so those can be translated too. | |
80 | # | |
81 | # All in one huge awk script. | |
82 | ||
83 | echo "scanning for keywords and %e strings..." >&2 | |
84 | ||
85 | ( cd $srcdir | |
1a7b32a3 | 86 | lang_subdirs=`echo */config-lang.in | sed -e 's|config-lang\.in||g'` |
6ec3f553 NB |
87 | { for dir in "" config/ config/*/ $lang_subdirs |
88 | do for glob in '*.c' '*.h' '*.def' | |
89 | do eval echo $dir$glob | |
90 | done | |
91 | done; | |
6ec3f553 | 92 | } | tr ' ' "$nl" | grep -v '\*' | |
4b794eaf | 93 | $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v kopt2=$kopt2 -v emsg=$emsg ' |
5b7874aa ZW |
94 | function keyword_option(line) { |
95 | paren_index = index(line, "(") | |
96 | name = substr(line, 1, paren_index - 1) | |
97 | sub(/[^0-9A-Z_a-z]*$/, "", name) | |
98 | sub(/[ ]+PARAMS/, "", name) | |
99 | sub(/[ ]+VPARAMS/, "", name) | |
100 | sub(/.*[^0-9A-Z_a-z]/, "", name) | |
101 | ||
102 | args = substr(line, paren_index) | |
103 | sub(/msgid[,\)].*/, "", args) | |
104 | for (n = 1; sub(/^[^,]*,/, "", args); n++) { | |
105 | continue | |
106 | } | |
4b794eaf JJ |
107 | format="" |
108 | if (args ~ /g$/) | |
109 | format="gcc-internal-format" | |
31043f6c FXC |
110 | else if (args ~ /noc$/) |
111 | format="no-c-format" | |
4b794eaf JJ |
112 | else if (args ~ /c$/) |
113 | format="c-format" | |
114 | ||
115 | if (n == 1) { keyword = "--keyword=" name } | |
116 | else { keyword = "--keyword=" name ":" n } | |
117 | if (format) { | |
118 | keyword=keyword "\n--flag=" name ":" n ":" format | |
119 | } | |
5b7874aa | 120 | |
4b794eaf JJ |
121 | if (! keyword_seen[name]) { |
122 | if (format == "gcc-internal-format") | |
123 | print keyword > kopt2 | |
124 | else | |
125 | print keyword > kopt | |
126 | keyword_seen[name] = keyword | |
127 | } else if (keyword_seen[name] != keyword) { | |
128 | printf("%s used incompatibly as both %s and %s\n", | |
129 | name, keyword_seen[name], keyword) | |
130 | exit (1) | |
5b7874aa ZW |
131 | } |
132 | } | |
133 | ||
134 | function spec_error_string (line) { | |
135 | while ((percent_index = index(line, "%e")) != 0) { | |
136 | escape = substr(line, percent_index - 1, 1) | |
137 | line = substr(line, percent_index + 2) | |
b4117c30 | 138 | if (escape == "%") continue |
5b7874aa ZW |
139 | |
140 | bracket_index = index(line, "}") | |
b4117c30 | 141 | quote_index = index(line, "\"") |
5b7874aa | 142 | if (bracket_index == 0) return |
b4117c30 | 143 | if (quote_index != 0 && bracket_index > quote_index) return |
5b7874aa ZW |
144 | |
145 | msgid = substr(line, 1, bracket_index - 1) | |
b4117c30 ZW |
146 | line = substr(line, bracket_index + 1) |
147 | ||
148 | if (index(msgid, "%") != 0) continue | |
5b7874aa ZW |
149 | |
150 | printf("#line %d \"%s\"\n", lineno, file) > emsg | |
151 | printf("_(\"%s\")\n", msgid) > emsg | |
152 | ||
5b7874aa ZW |
153 | } |
154 | } | |
155 | ||
156 | BEGIN { | |
157 | while ((getline < excl) > 0) { | |
158 | if ($0 ~ /^#/ || $0 ~ /^[ ]*$/) | |
159 | continue | |
160 | excludes[$1] = 1 | |
161 | } | |
162 | } | |
163 | ||
164 | { if (!($0 in excludes)) { | |
165 | print > posr | |
166 | files[NR] = $0 | |
167 | } | |
168 | } | |
169 | ||
170 | END { | |
171 | for (f in files) { | |
172 | file = files[f] | |
173 | lineno = 1 | |
174 | while (getline < file) { | |
175 | if (/^(#[ ]*define[ ]*)?[A-Za-z_].*\(.*msgid[,\)]/) { | |
176 | keyword_option($0) | |
177 | } else if (/%e/) { | |
178 | spec_error_string($0) | |
179 | } | |
180 | lineno++ | |
181 | } | |
182 | } | |
183 | print emsg > posr | |
184 | }' | |
4b794eaf | 185 | ) || exit |
5b7874aa | 186 | |
fb72a0a3 RS |
187 | echo "scanning option files..." >&2 |
188 | ||
189 | ( cd $srcdir; find . -name '*.opt' -print | | |
190 | $AWK '{ | |
191 | file = $1 | |
192 | lineno = 1 | |
193 | field = 0 | |
194 | while (getline < file) { | |
195 | if (/^[ \t]*(;|$)/ || !/^[^ \t]/) { | |
196 | field = 0 | |
197 | } else { | |
198 | if (field == 2) { | |
199 | line = $0 | |
200 | gsub(".*\t", "", line) | |
201 | printf("#line %d \"%s\"\n", lineno, file) | |
202 | printf("_(\"%s\")\n", line) | |
203 | } | |
204 | field++; | |
205 | } | |
206 | lineno++; | |
207 | } | |
208 | }') >> $emsg | |
209 | ||
5b7874aa ZW |
210 | # Run the xgettext command, with temporary added as a file to scan. |
211 | echo "running xgettext..." >&2 | |
212 | $xgettext --default-domain=$package --directory=$srcdir \ | |
213 | --add-comments `cat $kopt` --files-from=$posr \ | |
8d98c44c JM |
214 | --copyright-holder="Free Software Foundation, Inc." \ |
215 | --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \ | |
4b794eaf JJ |
216 | --language=c -o $pottmp1 |
217 | $xgettext --default-domain=$package --directory=$srcdir \ | |
218 | --add-comments --keyword= `cat $kopt2` --files-from=$posr \ | |
219 | --copyright-holder="Free Software Foundation, Inc." \ | |
220 | --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \ | |
221 | --language=GCC-source -o $pottmp2 | |
222 | $xgettext --default-domain=$package \ | |
223 | --add-comments $pottmp1 $pottmp2 \ | |
224 | --copyright-holder="Free Software Foundation, Inc." \ | |
225 | --msgid-bugs-address="http://gcc.gnu.org/bugs.html" \ | |
226 | --language=PO -o $pottmp | |
c043fab8 | 227 | # Remove local paths from .pot file. |
4b794eaf | 228 | sed "s:$srcdir/::g;s:$pwd/::g;" <$pottmp >po/$package.pot |