OSDN Git Service

* Makefile.in (.po.pox): Look both in srcdir and builddir
[pf3gnuchains/gcc-fork.git] / gcc / po / exgettext
1 #! /bin/sh
2 # Wrapper around gettext for GCC sources.
3 # Copyright 1998, 2001 Free Software Foundation, Inc.
4
5 # Written by Paul Eggert <eggert@twinsun.com>.
6 # Revised by Zack Weinberg <zackw@stanford.edu> for no-POTFILES operation.
7
8 # This file is part of GNU CC.
9
10 # GNU CC 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 2, or (at your option)
13 # any later version.
14
15 # GNU CC 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.
19
20 # You should have received a copy of the GNU General Public License
21 # along with GNU CC; see the file COPYING.  If not, write to
22 # the Free Software Foundation, 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA.
24
25 # Set environment to default value, if not already set.
26 : ${AWK=awk}
27
28 # The arguments to this wrapper are: the program to execute, the
29 # name of the "package", and the path to the source directory.
30
31 if [ $# -ne 3 ]
32 then    echo "usage: $0 <xgettext> <package> <srcdir>"
33         exit 1
34 fi
35
36 xgettext=$1
37 package=$2
38 srcdir=$3
39
40 nl='
41 '
42
43 set -e
44
45 # Create temporary directory for scratch files.
46 T=exg$$.d
47 mkdir $T
48 trap "rm -r $T" 0
49
50 pwd=`pwd`
51 kopt=$pwd/$T/keyword-options
52 emsg=$pwd/$T/emsgids.c
53 posr=$pwd/$T/po-sources
54
55 # Locate files to scan, and generate the list.  All .c and .h files in
56 # $srcdir are examined, likewise $srcdir/config and $srcdir/config/*
57 # (directories).  Also, all subdirectories of $srcdir that contain a
58 # config-lang.in.  Exclusions come from $srcdir/po/EXCLUDE.
59 #
60 # Then generate keyword options for xgettext, by scanning for declarations
61 # of functions whose parameter names end in "msgid".
62 #
63 # Finally, generate a source file containing all %e strings from
64 # driver specs, so those can be translated too.
65 #
66 # All in one huge awk script.
67
68 echo "scanning for keywords and %e strings..." >&2
69
70 ( cd $srcdir
71   lang_subdirs=`echo */config-lang.in | sed -e 's|/config-lang\.in||g'`
72   { echo *.[ch]
73     echo config/*.[ch]
74     echo config/*/*.[ch]
75     for l in $lang_subdirs
76     do  echo $l/*.[ch]
77     done
78   } | tr ' ' "$nl" | 
79   $AWK -v excl=po/EXCLUDES -v posr=$posr -v kopt=$kopt -v emsg=$emsg '
80 function keyword_option(line) {
81     paren_index = index(line, "(")
82     name = substr(line, 1, paren_index - 1)
83     sub(/[^0-9A-Z_a-z]*$/, "", name)
84     sub(/[       ]+PARAMS/, "", name)
85     sub(/[       ]+VPARAMS/, "", name)
86     sub(/.*[^0-9A-Z_a-z]/, "", name)
87
88     args = substr(line, paren_index)
89     sub(/msgid[,\)].*/, "", args)
90     for (n = 1; sub(/^[^,]*,/, "", args); n++) {
91         continue
92     }
93
94     if (n == 1) { keyword = name }
95     else        { keyword = name ":" n }
96
97     if (! keyword_seen[keyword]++) {
98         print "--keyword=" keyword > kopt
99     }
100 }
101
102 function spec_error_string (line) {
103     while ((percent_index = index(line, "%e")) != 0) {
104         escape = substr(line, percent_index - 1, 1)
105         line = substr(line, percent_index + 2)
106         if (escape == "%") return
107
108         bracket_index = index(line, "}")
109         if (bracket_index == 0) return
110
111         msgid = substr(line, 1, bracket_index - 1)
112         if (index(msgid, "%") != 0) return
113
114         printf("#line %d \"%s\"\n", lineno, file) > emsg
115         printf("_(\"%s\")\n", msgid) > emsg
116
117         line = substr(line, bracket_index + 1)
118     }
119 }
120
121 BEGIN {
122   while ((getline < excl) > 0) {
123     if ($0 ~ /^#/ || $0 ~ /^[   ]*$/)
124       continue
125     excludes[$1] = 1
126   }
127 }
128
129 { if (!($0 in excludes)) {
130     print > posr
131     files[NR] = $0
132   }
133 }
134
135 END {
136     for (f in files) {
137         file = files[f]
138         lineno = 1
139         while (getline < file) {
140             if (/^(#[   ]*define[       ]*)?[A-Za-z_].*\(.*msgid[,\)]/) {
141                 keyword_option($0)
142             } else if (/%e/) {
143                 spec_error_string($0)
144             }
145             lineno++
146         }
147     }
148     print emsg > posr
149 }'
150 )
151
152 # Run the xgettext command, with temporary added as a file to scan.
153 echo "running xgettext..." >&2
154 $xgettext --default-domain=$package --directory=$srcdir \
155           --add-comments `cat $kopt` --files-from=$posr \
156           -o po/$package.pot