* Makefile.in (rtlanal.o): Depend on $(TM_P_H).
[official-gcc.git] / gcc / exgettext
blob7b652de06c020f13a90ad47f40ee8a2b77c123f9
1 #! /bin/sh
2 # Wrapper around gettext for GCC sources.
3 # Copyright 1998 Free Software Foundation, Inc.
5 # Written by Paul Eggert <eggert@twinsun.com>.
7 # This file is part of GCC.
9 # GCC is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 2, or (at your option) any later
12 # version.
14 # GCC is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 # License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GCC; see the file COPYING. If not, write to the Free
21 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 # 02111-1307, USA.
24 # Set environment to default value, if not already set.
25 : ${AWK=awk}
27 # The argument to this wrapper is the xgettext command to be executed.
28 # Extract the xgettext program name from the rest of the command.
29 xgettext=${1?}
30 shift
32 # Save work if we're just wrapping a no-op.
33 case $xgettext in
34 :) exit;;
35 esac
37 # Find the files to be scanned, and the directory to scan them from.
38 directory=.
39 files=
40 for i
42 case $i in
43 --directory=*)
44 directory=`expr " $i" : ' --directory=\(.*\)'`;;
45 --files-from=*)
46 files_from=`expr " $i" : ' --files-from=\(.*\)'`
47 files=`$AWK '/^[^#]/ { print }' $files_from`;;
48 esac
49 done
51 # Generate keyword options for xgettext,
52 # by scanning for declarations of functions
53 # whose parameter names end in "msgid".
54 generate_keyword_options='
55 /^[A-Z_a-z].*\(.*msgid[,)]/ {
57 paren_index = index($0, "(")
59 name = substr($0, 1, paren_index - 1)
60 sub(/[^0-9A-Z_a-z]*$/, "", name)
61 sub(/[ ]+PARAMS/, "", name)
62 sub(/[ ]+VPARAMS/, "", name)
63 sub(/.*[^0-9A-Z_a-z]/, "", name)
65 args = substr($0, paren_index)
66 sub(/msgid[,)].*/, "", args)
67 for (n = 1; sub(/^[^,]*,/, "", args); n++) {
68 continue;
71 if (n == 1) {
72 keyword = name
73 } else {
74 keyword = name ":" n
77 if (! keyword_seen[keyword]++) {
78 print "--keyword=" keyword
82 keyword_options=`(
83 cd $directory &&
84 $AWK "$generate_keyword_options" $files < /dev/null
85 )` || exit
87 # Generate temporary file reflecting the %e strings in the scanned files.
88 tmp=tmp-emsgids.c
90 generate_emsgids='
91 /%e.*}/ {
92 line = $0
93 while ((percent_index = index(line, "%e")) != 0) {
94 line = substr(line, percent_index + 2)
95 bracket_index = index(line, "}")
96 if (bracket_index == 0) {
97 continue
99 msgid = substr(line, 1, bracket_index - 1)
100 if (index(msgid, "%") != 0) {
101 continue
103 printf "#line %d \"%s\"\n", FNR, FILENAME
104 printf "_(\"%s\")\n", msgid
105 line = substr(line, bracket_index + 1)
109 (cd $directory &&
110 $AWK "$generate_emsgids" $files < /dev/null
111 ) > $directory/$tmp || exit
113 # Run the xgettext command, with temporary added as a file to scan.
114 "$xgettext" $keyword_options ${1+"$@"} $tmp || exit
116 # Clean up.
117 # If we don't get here, `make clean' will remove this file later.
118 rm -f $directory/$tmp