]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genren/genren.pl
3 #*******************************************************************************
4 #* Copyright (C) 2001-2010, International Business Machines
5 #* Corporation and others. All Rights Reserved.
6 #*******************************************************************************
8 #* file name: genren.pl
10 #* tab size: 8 (not used)
13 #* Created by: Vladimir Weinstein
16 #* Used to generate renaming headers.
17 #* Run on UNIX platforms (linux) in order to catch all the exports
19 use POSIX
qw(strftime);
21 $headername = 'urename.h';
23 $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h";
30 (-e
$path) || die "Cannot find uversion.h";
32 open(UVERSION
, $path);
35 if(/\#define U_ICU_VERSION_SUFFIX/) {
37 s/\#define U_ICU_VERSION_SUFFIX //;
38 $U_ICU_VERSION_SUFFIX = "$_";
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
48 /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts
49 /^-p/ && (($post = shift (@ARGV)), next); # nm opts
50 /^-x/ && (($mode = shift (@ARGV)), next); # nm opts
51 /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix
52 warn("Invalid option $_\n");
57 warn "No libraries, exiting...\n";
61 #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h";
63 $HEADERDEF = uc($headername); # this is building the constant for #define
64 $HEADERDEF =~ s/\./_/;
67 open HEADER
, ">$headername"; # opening a header file
69 #We will print our copyright here + warnings
71 $YEAR = strftime
"%Y",localtime;
73 print HEADER
<<"EndOfHeaderComment";
75 *******************************************************************************
76 * Copyright (C) 2002-$YEAR, International Business Machines
77 * Corporation and others. All Rights Reserved.
78 *******************************************************************************
80 * file name: $headername
82 * tab size: 8 (not used)
85 * Created by: Perl script written by Vladimir Weinstein
87 * Contains data for renaming ICU exports.
88 * Gets included by umachine.h
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!
97 /* Uncomment the following line to disable renaming on platforms
98 that do not use Autoconf. */
99 /* #define U_DISABLE_RENAMING 1 */
101 #if !U_DISABLE_RENAMING
103 /* 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
104 the platform a chance to define it first.
105 Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined.
107 #ifndef U_ICU_ENTRY_POINT_RENAME
108 #include "unicode/umachine.h"
111 /* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */
112 #ifndef U_ICU_ENTRY_POINT_RENAME
113 #include "unicode/uvernum.h"
116 /* Error out before the following defines cause very strange and unexpected code breakage */
117 #ifndef U_ICU_ENTRY_POINT_RENAME
118 #error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used.
127 for(;@ARGV; shift(@ARGV)) {
129 @NMRESULT = `nm $nmopts $ARGV[0] $post`;
131 warn "Couldn't do 'nm' for $ARGV[0], continuing...\n";
132 next; # Couldn't do nm for the file
134 if($mode =~ /POSIX/) {
135 splice @NMRESULT, 0, 6;
136 } elsif ($mode =~ /Mach-O/) {
137 # splice @NMRESULT, 0, 10;
139 foreach (@NMRESULT) { # Process every line of result and stuff it in $_
141 if($mode =~ /POSIX/) {
142 ($_, $address, $type) = split(/\|/);
143 } elsif ($mode =~ /Mach-O/) {
144 if(/^(?:[0-9a-fA-F]){8} ([A-Z]) (?:_)?(.*)$/) {
145 ($_, $type) = ($2, $1);
150 die "Unknown mode $mode";
152 &verbose( "type: \"$type\" ");
153 if(!($type =~ /[UAwW?]/)) {
154 if(/@@/) { # These would be imports
155 &verbose( "Import: $_ \"$type\"\n");
156 &verbose( "C++ method: $_\n");
157 } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array
158 ## DON'T match ... ( foo::bar ... want :: to be to the left of paren
159 ## icu_2_0::CharString::~CharString(void) -> CharString
160 @CppName = split(/::/); ## remove scope stuff
162 ## MessageFormat virtual table -> MessageFormat
163 @CppName = split(/ /, $CppName[1]); ## remove debug stuff
165 ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex
166 @CppName = split(/\(/, $CppName[0]); ## remove function args
167 if($CppName[0] =~ /^operator/) {
168 &verbose ("Skipping C++ function: $_\n");
169 } elsif($CppName[0] =~ /^~/) {
170 &verbose ("Skipping C++ destructor: $_\n");
172 &verbose( " Class: '$CppName[0]': $_ \n");
173 $CppClasses{$CppName[0]}++;
176 } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) {
177 &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" );
180 } elsif ( /\(/) { # These are strange functions
181 print STDERR "$ARGV[0]: Not sure what to do with '$_'\n";
182 } elsif ( /^_init/ ) {
183 &verbose( "$ARGV[0]: Skipped initializer $_\n" );
184 } elsif ( /^_fini/ ) {
185 &verbose( "$ARGV[0]: Skipped finilizer $_\n" );
187 print STDERR "$ARGV[0]: Skipped strange mangled function $_\n";
188 } elsif ( /^vtable for /) {
189 print STDERR "$ARGV[0]: Skipped vtable $_\n";
190 } elsif ( /^typeinfo for /) {
191 print STDERR "$ARGV[0]: Skipped typeinfo $_\n";
192 } elsif ( /operator\+/ ) {
193 print STDERR "$ARGV[0]: Skipped ignored function $_\n";
194 } else { # This is regular C function
195 &verbose( "C func: $_\n");
196 @funcname = split(/[\(\s+]/);
197 $CFuncs{$funcname[0]}++;
201 &verbose( "Skipped: $_ $1\n");
206 if( $fileCount == 0 ) {
207 die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
210 if( $symbolCount == 0 ) {
211 die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
214 print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n";
216 print HEADER "\n/* C exports renaming data */\n\n";
217 foreach(sort keys(%CFuncs)) {
218 print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n";
219 # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n";
223 print HEADER "/* C++ class names renaming defines */\n\n";
224 print HEADER "#ifdef XP_CPLUSPLUS\n";
225 print HEADER "#if !U_HAVE_NAMESPACE\n\n";
226 foreach(sort keys(%CppClasses)) {
227 print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n";
229 print HEADER "\n#endif\n";
230 print HEADER "#endif\n";
231 print HEADER "\n#endif\n";
232 print HEADER "\n#endif\n";
243 sub printHelpMsgAndExit {
244 print STDERR <<"EndHelpText";
245 Usage: $0 [OPTIONS] LIBRARY_FILES
249 -o - output file name (defaults to 'urename.h'
250 -S - suffix (defaults to _MAJOR_MINOR of current ICU version)
251 Will produce a renaming .h file