]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genren/genren.pl
2 # Copyright (C) 2016 and later: Unicode, Inc. and others.
3 # License & terms of use: http://www.unicode.org/copyright.html
5 #*******************************************************************************
6 #* Copyright (C) 2001-2012, International Business Machines
7 #* Corporation and others. All Rights Reserved.
8 #*******************************************************************************
10 #* file name: genren.pl
12 #* tab size: 8 (not used)
15 #* Created by: Vladimir Weinstein
18 #* Used to generate renaming headers.
19 #* Run on UNIX platforms (linux) in order to catch all the exports
21 use POSIX
qw(strftime);
23 $headername = 'urename.h';
25 $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h";
32 (-e
$path) || die "Cannot find uversion.h";
34 open(UVERSION
, $path);
37 if(/\#define U_ICU_VERSION_SUFFIX/) {
39 s/\#define U_ICU_VERSION_SUFFIX //;
40 $U_ICU_VERSION_SUFFIX = "$_";
45 while($ARGV[0] =~ /^-/) { # detects whether there are any arguments
46 $_ = shift @ARGV; # extracts the argument for processing
47 /^-v/ && ($VERBOSE++, next); # verbose
48 /^-h/ && (&printHelpMsgAndExit
, next); # help
49 /^-o/ && (($headername = shift (@ARGV)), next); # output file
50 /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts
51 /^-p/ && (($post = shift (@ARGV)), next); # nm opts
52 /^-x/ && (($mode = shift (@ARGV)), next); # nm opts
53 /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix
54 warn("Invalid option $_\n");
59 warn "No libraries, exiting...\n";
63 #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h";
65 $HEADERDEF = uc($headername); # this is building the constant for #define
66 $HEADERDEF =~ s/\./_/;
69 open HEADER
, ">$headername"; # opening a header file
71 #We will print our copyright here + warnings
73 print HEADER
<<"EndOfHeaderComment";
74 // © 2016 and later: Unicode, Inc. and others.
75 // License & terms of use: http://www.unicode.org/copyright.html
77 *******************************************************************************
78 * Copyright (C) 2002-2016, International Business Machines
79 * Corporation and others. All Rights Reserved.
80 *******************************************************************************
82 * file name: $headername
84 * tab size: 8 (not used)
87 * Created by: Perl script tools/genren.pl written by Vladimir Weinstein
89 * Contains data for renaming ICU exports.
90 * Gets included by umachine.h
92 * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT
93 * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN!
99 /* U_DISABLE_RENAMING can be defined in the following ways:
100 * - when running configure, e.g.
101 * runConfigureICU Linux --disable-renaming
102 * - by changing the default setting of U_DISABLE_RENAMING in uconfig.h
105 #include "unicode/uconfig.h"
107 #if !U_DISABLE_RENAMING
109 /* 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
110 the platform a chance to define it first.
111 Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined.
114 #ifndef U_ICU_ENTRY_POINT_RENAME
115 #include "unicode/umachine.h"
118 /* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */
119 #ifndef U_ICU_ENTRY_POINT_RENAME
120 #include "unicode/uvernum.h"
123 /* Error out before the following defines cause very strange and unexpected code breakage */
124 #ifndef U_ICU_ENTRY_POINT_RENAME
125 #error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used.
134 for(;@ARGV; shift(@ARGV)) {
136 @NMRESULT = `nm $nmopts $ARGV[0] $post`;
138 warn "Couldn't do 'nm' for $ARGV[0], continuing...\n";
139 next; # Couldn't do nm for the file
141 if($mode =~ /POSIX/) {
142 splice @NMRESULT, 0, 6;
143 } elsif ($mode =~ /Mach-O/) {
144 # splice @NMRESULT, 0, 10;
146 foreach (@NMRESULT) { # Process every line of result and stuff it in $_
148 if($mode =~ /POSIX/) {
150 ($_, $address, $type) = split(/\|/);
152 } elsif ($mode =~ /Mach-O/) {
153 ($address, $type, $_) = split(/ /);
160 die "Unknown mode $mode";
162 &verbose( "type: \"$type\" ");
163 if(!($type =~ /[UAwW?]/)) {
164 if(/@@/) { # These would be imports
165 &verbose( "Import: $_ \"$type\"\n");
166 &verbose( "C++ method: $_\n");
167 } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array
168 ## DON'T match ... ( foo::bar ... want :: to be to the left of paren
169 ## icu::CharString::~CharString(void) -> CharString
170 @CppName = split(/::/); ## remove scope stuff
173 ## MessageFormat virtual table -> MessageFormat
174 if(! ($CppName[0] =~ /icu/ )) {
175 # *** WARNING Bad namespace (not 'icu') on ShoeSize::ShoeSize()
176 warn "*** WARNING Bad namespace (not 'icu') on $_\n";
179 &verbose ( "(Chopping scope $CppName[0] )");
180 @CppName = split(/ /, $CppName[1]); ## remove debug stuff
182 ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex
183 @CppName = split(/\(/, $CppName[0]); ## remove function args
184 if($CppName[0] =~ /^operator/) {
185 &verbose ("Skipping C++ function: $_\n");
186 } elsif($CppName[0] =~ /^~/) {
187 &verbose ("Skipping C++ destructor: $_\n");
189 &verbose( "Skipping C++ class: '$CppName[0]': $_ \n");
190 # $CppClasses{$CppName[0]}++;
193 } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) {
194 &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" );
197 } elsif ( /\(/) { # These are strange functions
198 print STDERR "$ARGV[0]: Not sure what to do with '$_'\n";
199 } elsif ( /^_init/ ) {
200 &verbose( "$ARGV[0]: Skipped initializer $_\n" );
201 } elsif ( /^_fini/ ) {
202 &verbose( "$ARGV[0]: Skipped finilizer $_\n" );
204 print STDERR "$ARGV[0]: Skipped strange mangled function $_\n";
205 } elsif ( /^vtable for /) {
206 print STDERR "$ARGV[0]: Skipped vtable $_\n";
207 } elsif ( /^typeinfo/) {
208 print STDERR "$ARGV[0]: Skipped typeinfo $_\n";
209 } elsif ( /operator\+/ ) {
210 print STDERR "$ARGV[0]: Skipped ignored function $_\n";
211 } else { # This is regular C function
212 &verbose( "C func: $_\n");
213 @funcname = split(/[\(\s+]/);
214 $CFuncs{$funcname[0]}++;
218 &verbose( "Skipped: $_ $1\n");
223 if( $fileCount == 0 ) {
224 die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
227 if( $symbolCount == 0 ) {
228 die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n";
231 print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n";
233 print HEADER "\n/* C exports renaming data */\n\n";
234 foreach(sort keys(%CFuncs)) {
235 print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n";
236 # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n";
239 print HEADER "\n#endif\n";
240 print HEADER "\n#endif\n";
251 sub printHelpMsgAndExit {
252 print STDERR <<"EndHelpText";
253 Usage: $0 [OPTIONS] LIBRARY_FILES
257 -o - output file name (defaults to 'urename.h'
258 -S - suffix (defaults to _MAJOR_MINOR of current ICU version)
259 Will produce a renaming .h file