]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | #!/usr/bin/perl |
2 | #* | |
3 | #******************************************************************************* | |
51004dcb | 4 | #* Copyright (C) 2001-2012, International Business Machines |
b75a7d8f A |
5 | #* Corporation and others. All Rights Reserved. |
6 | #******************************************************************************* | |
7 | #* | |
8 | #* file name: genren.pl | |
9 | #* encoding: US-ASCII | |
10 | #* tab size: 8 (not used) | |
11 | #* indentation:4 | |
12 | #* | |
13 | #* Created by: Vladimir Weinstein | |
14 | #* 07/19/2001 | |
15 | #* | |
16 | #* Used to generate renaming headers. | |
17 | #* Run on UNIX platforms (linux) in order to catch all the exports | |
18 | ||
729e4ab9 A |
19 | use POSIX qw(strftime); |
20 | ||
b75a7d8f A |
21 | $headername = 'urename.h'; |
22 | ||
23 | $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h"; | |
24 | ||
46f4442e A |
25 | $nmopts = '-Cg -f s'; |
26 | $post = ''; | |
27 | ||
729e4ab9 | 28 | $mode = 'POSIX'; |
46f4442e | 29 | |
b75a7d8f A |
30 | (-e $path) || die "Cannot find uversion.h"; |
31 | ||
32 | open(UVERSION, $path); | |
33 | ||
34 | while(<UVERSION>) { | |
35 | if(/\#define U_ICU_VERSION_SUFFIX/) { | |
36 | chop; | |
37 | s/\#define U_ICU_VERSION_SUFFIX //; | |
38 | $U_ICU_VERSION_SUFFIX = "$_"; | |
39 | last; | |
40 | } | |
41 | } | |
42 | ||
43 | while($ARGV[0] =~ /^-/) { # detects whether there are any arguments | |
44 | $_ = shift @ARGV; # extracts the argument for processing | |
45 | /^-v/ && ($VERBOSE++, next); # verbose | |
46 | /^-h/ && (&printHelpMsgAndExit, next); # help | |
47 | /^-o/ && (($headername = shift (@ARGV)), next); # output file | |
46f4442e A |
48 | /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts |
49 | /^-p/ && (($post = shift (@ARGV)), next); # nm opts | |
50 | /^-x/ && (($mode = shift (@ARGV)), next); # nm opts | |
b75a7d8f A |
51 | /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix |
52 | warn("Invalid option $_\n"); | |
53 | &printHelpMsgAndExit; | |
54 | } | |
55 | ||
56 | unless(@ARGV > 0) { | |
57 | warn "No libraries, exiting...\n"; | |
58 | &printHelpMsgAndExit; | |
59 | } | |
60 | ||
61 | #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h"; | |
62 | ||
63 | $HEADERDEF = uc($headername); # this is building the constant for #define | |
64 | $HEADERDEF =~ s/\./_/; | |
65 | ||
66 | ||
67 | open HEADER, ">$headername"; # opening a header file | |
68 | ||
69 | #We will print our copyright here + warnings | |
729e4ab9 A |
70 | |
71 | $YEAR = strftime "%Y",localtime; | |
72 | ||
b75a7d8f A |
73 | print HEADER <<"EndOfHeaderComment"; |
74 | /* | |
75 | ******************************************************************************* | |
729e4ab9 | 76 | * Copyright (C) 2002-$YEAR, International Business Machines |
b75a7d8f A |
77 | * Corporation and others. All Rights Reserved. |
78 | ******************************************************************************* | |
79 | * | |
80 | * file name: $headername | |
81 | * encoding: US-ASCII | |
82 | * tab size: 8 (not used) | |
83 | * indentation:4 | |
84 | * | |
51004dcb | 85 | * Created by: Perl script tools/genren.pl written by Vladimir Weinstein |
b75a7d8f A |
86 | * |
87 | * Contains data for renaming ICU exports. | |
88 | * Gets included by umachine.h | |
89 | * | |
90 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT | |
91 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! | |
92 | */ | |
93 | ||
94 | #ifndef $HEADERDEF | |
95 | #define $HEADERDEF | |
96 | ||
51004dcb A |
97 | /* U_DISABLE_RENAMING can be defined in the following ways: |
98 | * - when running configure, e.g. | |
99 | * runConfigureICU Linux --disable-renaming | |
100 | * - by changing the default setting of U_DISABLE_RENAMING in uconfig.h | |
101 | */ | |
102 | ||
103 | #include "unicode/uconfig.h" | |
b75a7d8f A |
104 | |
105 | #if !U_DISABLE_RENAMING | |
729e4ab9 A |
106 | |
107 | /* We need the U_ICU_ENTRY_POINT_RENAME definition. There's a default one in unicode/uvernum.h we can use, but we will give | |
108 | the platform a chance to define it first. | |
109 | Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined. | |
110 | */ | |
4388f060 | 111 | |
729e4ab9 A |
112 | #ifndef U_ICU_ENTRY_POINT_RENAME |
113 | #include "unicode/umachine.h" | |
114 | #endif | |
115 | ||
116 | /* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */ | |
117 | #ifndef U_ICU_ENTRY_POINT_RENAME | |
118 | #include "unicode/uvernum.h" | |
119 | #endif | |
120 | ||
121 | /* Error out before the following defines cause very strange and unexpected code breakage */ | |
122 | #ifndef U_ICU_ENTRY_POINT_RENAME | |
123 | #error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used. | |
124 | #endif | |
125 | ||
b75a7d8f A |
126 | EndOfHeaderComment |
127 | ||
729e4ab9 A |
128 | $fileCount = 0; |
129 | $itemCount = 0; | |
130 | $symbolCount = 0; | |
131 | ||
b75a7d8f | 132 | for(;@ARGV; shift(@ARGV)) { |
729e4ab9 | 133 | $fileCount++; |
46f4442e | 134 | @NMRESULT = `nm $nmopts $ARGV[0] $post`; |
b75a7d8f A |
135 | if($?) { |
136 | warn "Couldn't do 'nm' for $ARGV[0], continuing...\n"; | |
137 | next; # Couldn't do nm for the file | |
138 | } | |
46f4442e A |
139 | if($mode =~ /POSIX/) { |
140 | splice @NMRESULT, 0, 6; | |
141 | } elsif ($mode =~ /Mach-O/) { | |
142 | # splice @NMRESULT, 0, 10; | |
143 | } | |
b75a7d8f | 144 | foreach (@NMRESULT) { # Process every line of result and stuff it in $_ |
729e4ab9 | 145 | $itemCount++; |
46f4442e | 146 | if($mode =~ /POSIX/) { |
4388f060 | 147 | &verbose(" $_"); |
46f4442e | 148 | ($_, $address, $type) = split(/\|/); |
4388f060 | 149 | chop $qtype; |
46f4442e | 150 | } elsif ($mode =~ /Mach-O/) { |
51004dcb A |
151 | ($address, $type, $_) = split(/ /); |
152 | if(/^_(.*)$/) { | |
153 | $_ = $1; | |
46f4442e A |
154 | } else { |
155 | next; | |
156 | } | |
157 | } else { | |
158 | die "Unknown mode $mode"; | |
159 | } | |
b75a7d8f A |
160 | &verbose( "type: \"$type\" "); |
161 | if(!($type =~ /[UAwW?]/)) { | |
162 | if(/@@/) { # These would be imports | |
163 | &verbose( "Import: $_ \"$type\"\n"); | |
b75a7d8f | 164 | &verbose( "C++ method: $_\n"); |
729e4ab9 A |
165 | } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array |
166 | ## DON'T match ... ( foo::bar ... want :: to be to the left of paren | |
4388f060 | 167 | ## icu::CharString::~CharString(void) -> CharString |
b75a7d8f | 168 | @CppName = split(/::/); ## remove scope stuff |
4388f060 | 169 | |
b75a7d8f A |
170 | if(@CppName>1) { |
171 | ## MessageFormat virtual table -> MessageFormat | |
4388f060 A |
172 | if(! ($CppName[0] =~ /icu/ )) { |
173 | # *** WARNING Bad namespace (not 'icu') on ShoeSize::ShoeSize() | |
174 | warn "*** WARNING Bad namespace (not 'icu') on $_\n"; | |
175 | next; | |
176 | } | |
177 | &verbose ( "(Chopping scope $CppName[0] )"); | |
b75a7d8f A |
178 | @CppName = split(/ /, $CppName[1]); ## remove debug stuff |
179 | } | |
180 | ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex | |
181 | @CppName = split(/\(/, $CppName[0]); ## remove function args | |
46f4442e A |
182 | if($CppName[0] =~ /^operator/) { |
183 | &verbose ("Skipping C++ function: $_\n"); | |
184 | } elsif($CppName[0] =~ /^~/) { | |
185 | &verbose ("Skipping C++ destructor: $_\n"); | |
186 | } else { | |
4388f060 A |
187 | &verbose( "Skipping C++ class: '$CppName[0]': $_ \n"); |
188 | # $CppClasses{$CppName[0]}++; | |
189 | # $symbolCount++; | |
46f4442e | 190 | } |
729e4ab9 A |
191 | } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) { |
192 | &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" ); | |
193 | $CFuncs{$cfn}++; | |
194 | $symbolCount++; | |
b75a7d8f | 195 | } elsif ( /\(/) { # These are strange functions |
729e4ab9 A |
196 | print STDERR "$ARGV[0]: Not sure what to do with '$_'\n"; |
197 | } elsif ( /^_init/ ) { | |
198 | &verbose( "$ARGV[0]: Skipped initializer $_\n" ); | |
199 | } elsif ( /^_fini/ ) { | |
200 | &verbose( "$ARGV[0]: Skipped finilizer $_\n" ); | |
b75a7d8f | 201 | } elsif ( /icu_/) { |
729e4ab9 | 202 | print STDERR "$ARGV[0]: Skipped strange mangled function $_\n"; |
46f4442e | 203 | } elsif ( /^vtable for /) { |
729e4ab9 | 204 | print STDERR "$ARGV[0]: Skipped vtable $_\n"; |
4388f060 | 205 | } elsif ( /^typeinfo/) { |
729e4ab9 | 206 | print STDERR "$ARGV[0]: Skipped typeinfo $_\n"; |
46f4442e | 207 | } elsif ( /operator\+/ ) { |
729e4ab9 | 208 | print STDERR "$ARGV[0]: Skipped ignored function $_\n"; |
b75a7d8f A |
209 | } else { # This is regular C function |
210 | &verbose( "C func: $_\n"); | |
211 | @funcname = split(/[\(\s+]/); | |
212 | $CFuncs{$funcname[0]}++; | |
729e4ab9 | 213 | $symbolCount++; |
b75a7d8f A |
214 | } |
215 | } else { | |
216 | &verbose( "Skipped: $_ $1\n"); | |
217 | } | |
218 | } | |
219 | } | |
220 | ||
729e4ab9 A |
221 | if( $fileCount == 0 ) { |
222 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; | |
223 | } | |
224 | ||
225 | if( $symbolCount == 0 ) { | |
226 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; | |
227 | } | |
228 | ||
229 | print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n"; | |
230 | ||
b75a7d8f A |
231 | print HEADER "\n/* C exports renaming data */\n\n"; |
232 | foreach(sort keys(%CFuncs)) { | |
729e4ab9 A |
233 | print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n"; |
234 | # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; | |
b75a7d8f A |
235 | } |
236 | ||
b75a7d8f A |
237 | print HEADER "\n#endif\n"; |
238 | print HEADER "\n#endif\n"; | |
239 | ||
240 | close HEADER; | |
241 | ||
242 | sub verbose { | |
243 | if($VERBOSE) { | |
244 | print STDERR @_; | |
245 | } | |
246 | } | |
247 | ||
248 | ||
249 | sub printHelpMsgAndExit { | |
250 | print STDERR <<"EndHelpText"; | |
251 | Usage: $0 [OPTIONS] LIBRARY_FILES | |
252 | Options: | |
253 | -v - verbose | |
254 | -h - help | |
255 | -o - output file name (defaults to 'urename.h' | |
256 | -S - suffix (defaults to _MAJOR_MINOR of current ICU version) | |
257 | Will produce a renaming .h file | |
258 | ||
259 | EndHelpText | |
260 | ||
261 | exit 0; | |
262 | ||
263 | } |