]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genrb/gendtjar.pl
ICU-8.11.1.tar.gz
[apple/icu.git] / icuSources / tools / genrb / gendtjar.pl
1 #!/usr/bin/perl
2 # ********************************************************************
3 # * COPYRIGHT:
4 # * Copyright (c) 2002-2006, International Business Machines Corporation and
5 # * others. All Rights Reserved.
6 # ********************************************************************
7
8 # Script to generate the icudata.jar and testdata.jar files. This file is
9 # part of icu4j. It is checked into CVS. It is generated from
10 # locale data in the icu4c project. See usage() notes (below)
11 # for more information.
12
13 # This script requires perl. For Win32, I recommend www.activestate.com.
14
15 # Ram Viswanadha
16 # copied heavily from genrbjar.pl
17 use File::Find;
18 use File::Basename;
19 use IO::File;
20 use Cwd;
21 use File::Copy;
22 use Getopt::Long;
23 use File::Path;
24 use File::Copy;
25 use Cwd;
26 use Cwd 'abs_path';
27
28 main();
29
30 #------------------------------------------------------------------
31 sub main(){
32
33 GetOptions(
34 "--icu-root=s" => \$icuRootDir,
35 "--jar=s" => \$jarDir,
36 "--icu4j-root=s" => \$icu4jDir,
37 "--version=s" => \$version,
38 "--verbose" => \$verbose,
39 "--help" => \$help
40 );
41 $cwd = abs_path(getcwd);
42
43 if($help){
44 usage();
45 }
46 unless (defined $icuRootDir){
47 $icuRootDir =abs_path($cwd."/../../..");
48 }
49 unless (defined $icu4jDir){
50 $icu4jDir =abs_path($icuRootDir."/../icu4j");
51 }
52 unless (defined $jarDir){
53 if(defined $ENV{'JAVA_HOME'}){
54 $jarDir=$ENV{'JAVA_HOME'}."/bin";
55 }else{
56 print("ERROR: JAVA_HOME enviroment variable undefined and --jar argument not specifed.\n");
57 usage();
58 }
59 }
60
61 $platform = getPlatform();
62 $icuBinDir = $icuRootDir;
63
64 $path=$ENV{'PATH'};
65
66 if(($platform eq "cygwin") || ($platform eq "linux")){
67 $icuBinDir .= "/source/bin";
68 $icuLibDir = abs_path($icuBinDir."/../lib");
69 $path .=":$icuBinDir:$icuLibDir";
70
71 $libpath = $ENV{'LD_LIBRARY_PATH'}.":$icuLibDir";
72 $ENV{'LD_LIBRARY_PATH'} = $libpath;
73
74 #print ("##### LD_LIBRARY_PATH = $ENV{'LD_LIBRARY_PATH'}\n");
75
76 }elsif($platform eq "aix"){
77
78 $icuBinDir .= "/source/bin";
79 $icuLibDir = abs_path($icuBinDir."/../lib");
80 $path .=":$icuBinDir:$icuLibDir";
81
82 $libpath = $ENV{'LIBPATH'}.":$icuLibDir";
83 $ENV{'LIBPATH'} = $libpath;
84 #print ("##### LIBPATH = $ENV{'LIBPATH'}\n");
85 }elsif($platform eq "darwin"){
86 $icuBinDir .= "/source/bin";
87 $icuLibDir = abs_path($icuBinDir."/../lib");
88 $path .=":$icuBinDir:$icuLibDir";
89
90 $libpath = $ENV{'DYLD_LIBRARY_PATH'}.":$icuLibDir";
91 $ENV{'DYLD_LIBRARY_PATH'} = $libpath;
92
93 }elsif($platform eq "MSWin32"){
94 $icuBinDir =$icuRootDir."/bin";
95 $path .=$icuBinDir;
96
97 }
98 $ENV{'PATH'} = $path;
99 #print ("##### PATH = $ENV{'PATH'}\n");
100 # TODO add more platforms and test on Linux and Unix
101
102 $icuBuildDir =$icuRootDir."/source/data/out/build";
103 $icuTestDataDir =$icuRootDir."/source/test/testdata/out/build/";
104
105 # now build ICU
106 buildICU($platform, $icuRootDir, $icuTestDataDir, $verbose);
107
108 #figure out the version and endianess
109 unless (defined $version){
110 ($version, $endian) = getVersion();
111 #print "#################### $version, $endian ######\n";
112 }
113
114 $icuswap = $icuBinDir."/icuswap -tb";
115 $tempDir = $cwd."/temp";
116 $version =~ s/\.//;
117 $icu4jImpl = "com/ibm/icu/impl/data/";
118 $icu4jDataDir = $icu4jImpl."/icudt".$version."b";
119 $icu4jDevDataDir = "com/ibm/icu/dev/data/";
120 $icu4jTestDataDir = "$icu4jDevDataDir/testdata";
121
122 $icuDataDir =$icuBuildDir."/icudt".$version.checkPlatformEndianess();
123
124 convertData($icuDataDir, $icuswap, $tempDir, $icu4jDataDir, $verbose);
125 #convertData($icuDataDir."/coll/", $icuswap, $tempDir, $icu4jDataDir."/coll");
126 createJar("$jarDir/jar", "icudata.jar", $tempDir, $icu4jDataDir, $verbose);
127
128 convertTestData($icuTestDataDir, $icuswap, $tempDir, $icu4jTestDataDir, $verbose);
129 createJar("$jarDir/jar", "testdata.jar", $tempDir, $icu4jTestDataDir, $verbose);
130 copyData($icu4jDir, $icu4jImpl, $icu4jDevDataDir, $tempDir, $verbose);
131 }
132
133 #-----------------------------------------------------------------------
134 sub buildICU{
135 local($platform, $icuRootDir, $icuTestDataDir, $verbose) = @_;
136 $icuSrcDir = $icuRootDir."/source";
137 $icuSrcDataDir = $icuSrcDir."/data";
138
139 chdir($icuSrcDir);
140 # clean the data directories
141 unlink($icuBuildDir."../");
142 unlink($icuTestDataDir."../");
143
144 if(($platform eq "cygwin")||($platform eq "darwin")||($platform eq "linux")){
145 # make all in ICU
146 cmd("make all", $verbose);
147 chdir($icuSrcDataDir);
148 cmd("make uni-core-data", $verbose);
149 chdir($icuTestDataDir."../../");
150 #print($icuTestDataDir."../../\n");
151 cmd("make", $verbose);
152 }elsif($platform eq "aix"){
153 # make all in ICU
154 cmd("gmake all", $verbose);
155 chdir($icuSrcDataDir);
156 cmd("gmake uni-core-data", $verbose);
157 chdir($icuTestDataDir."../../");
158 cmd("gmake", $verbose);
159 }elsif($platform eq "MSWin32"){
160 #devenv.com $projectFileName \/build $configurationName > \"$cLogFile\" 2>&1
161 cmd("devenv.com allinone/allinone.sln /useenv /build Debug", $verbose);
162 # build required data. this is required coz building icu will not build all the data
163 chdir($icuSrcDataDir);
164 cmd("NMAKE /f makedata.mak ICUMAKE=\"$icuSrcDataDir\" CFG=debug uni-core-data", $verbose);
165
166 }else{
167 print "ERROR: Could not build ICU unknown platform $platform. \n";
168 exit(-1);
169 }
170
171 chdir($cwd);
172 }
173 #-----------------------------------------------------------------------
174 sub getVersion{
175 my @list;
176 opendir(DIR,$icuBuildDir);
177
178 @list = readdir(DIR);
179 closedir(DIR);
180
181 if(scalar(@list)>3){
182 print("ERROR: More than 1 directory in build. Can't decide the version");
183 exit(-1);
184 }
185 foreach $item (@list){
186 next if($item eq "." || $item eq "..");
187 my ($ver, $end) =$item =~ m/icudt(.*)(l|b|e)$/;
188 return $ver,$end;
189 }
190 }
191
192 #-----------------------------------------------------------------------
193 sub getPlatform{
194 $platform = $^O;
195 return $platform;
196 }
197 #-----------------------------------------------------------------------
198 sub createJar{
199 local($jar, $jarFile, $tempDir, $dirToJar, $verbose) = @_;
200 chdir($tempDir);
201 $command="";
202 print "INFO: Creating $jarFile\n";
203 if(defined $verbose){
204 $command = "$jar cvf $jarFile -C $tempDir $dirToJar";
205 }else{
206 $command = "$jar cf $jarFile -C $tempDir $dirToJar";
207 }
208
209 cmd($command, $verbose);
210 }
211 #-----------------------------------------------------------------------
212 sub checkPlatformEndianess {
213 my $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/;
214 if ($is_big_endian) {
215 return "b";
216 }else{
217 return "l";
218 }
219 }
220 #-----------------------------------------------------------------------
221 sub copyData{
222 local($icu4jDir, $icu4jImpl, $icu4jDevDataDir, $tempDir) =@_;
223 print("INFO: Copying $tempDir/icudata.jar to $icu4jDir/src/$icu4jImpl\n");
224 copy("$tempDir/icudata.jar", "$icu4jDir/src/$icu4jImpl");
225 print("INFO: Copying $tempDir/testdata.jar $icu4jDir/src/$icu4jDevDataDir\n");
226 copy("$tempDir/testdata.jar","$icu4jDir/src/$icu4jDevDataDir");
227 }
228 #-----------------------------------------------------------------------
229 sub convertData{
230 local($icuDataDir, $icuswap, $tempDir, $icu4jDataDir) =@_;
231 my $dir = $tempDir."/".$icu4jDataDir;
232 # create the temp directory
233 mkpath($dir) ;
234 # cd to the temp directory
235 chdir($tempDir);
236 my $endian = checkPlatformEndianess();
237 my @list;
238 opendir(DIR,$icuDataDir);
239 #print $icuDataDir;
240 @list = readdir(DIR);
241 closedir(DIR);
242 my $op = $icuswap;
243 #print "####### $endian ############\n";
244 if($endian eq "l"){
245 print "INFO: {Command: $op $icuDataDir/*.*}\n";
246 }else{
247 print "INFO: {Command: copy($icuDataDir/*.*, $tempDir/$icu4jDataDir/*)}\n";
248 }
249
250 $i=0;
251 # now convert
252 foreach $item (@list){
253 next if($item eq "." || $item eq "..");
254 # next if($item =~ /^t_.*$\.res/ ||$item =~ /^translit_.*$\.res/ ||
255 # $item=~/$\.crs/ || $item=~ /$\.txt/ ||
256 # $item=~/icudata\.res/ || $item=~/$\.exp/ || $item=~/$\.lib/ ||
257 # $item=~/$\.obj/ || $item=~/$\.lst/);
258 next if($item =~ /^t_.*$\.res/ ||$item =~ /^translit_.*$\.res/ || $item =~ /$\.cnv/ ||
259 $item=~/$\.crs/ || $item=~ /$\.txt/ ||
260 $item=~/icudata\.res/ || $item=~/$\.exp/ || $item=~/$\.lib/ || $item=~/$\.obj/ ||
261 $item=~/cnvalias\.icu/ || $item=~/$\.lst/);
262 if(-d "$icuDataDir/$item"){
263 convertData("$icuDataDir/$item/", $icuswap, $tempDir, "$icu4jDataDir/$item/");
264 next;
265 }
266 if($endian eq "l"){
267 $command = $icuswap." $icuDataDir/$item $tempDir/$icu4jDataDir/$item";
268 cmd($command, $verbose);
269 }else{
270 $rc = copy("$icuDataDir/$item", "$tempDir/$icu4jDataDir/$item");
271 if($rc==1){
272 #die "ERROR: Could not copy $icuDataDir/$item to $tempDir/$icu4jDataDir/$item, $!";
273 }
274 }
275
276 }
277 chdir("..");
278 print "INFO: DONE\n";
279 }
280 #-----------------------------------------------------------------------
281 sub convertTestData{
282 local($icuDataDir, $icuswap, $tempDir, $icu4jDataDir) =@_;
283 my $dir = $tempDir."/".$icu4jDataDir;
284 # create the temp directory
285 mkpath($dir);
286 # cd to the temp directory
287 chdir($tempDir);
288 my $op = $icuswap;
289 print "INFO: {Command: $op $icuDataDir/*.*}\n";
290 my @list;
291 opendir(DIR,$icuDataDir) or die "ERROR: Could not open the $icuDataDir directory for reading $!";
292 #print $icuDataDir;
293 @list = readdir(DIR);
294 closedir(DIR);
295 my $endian = checkPlatformEndianess();
296 $i=0;
297 # now convert
298 foreach $item (@list){
299 next if($item eq "." || $item eq "..");
300 next if($item =~ /$\.cnv/ || item=~/$\.crs/ || $item=~ /$\.txt/ ||
301 $item=~/$\.exp/ || $item=~/$\.lib/ || $item=~/$\.obj/ ||
302 $item=~/$\.mak/ || $item=~/test\.icu/ || $item=~/$\.lst/);
303 $file = $item;
304 $file =~ s/testdata_//g;
305 if($endian eq "l"){
306 $command = "$icuswap $icuDataDir/$item $tempDir/$icu4jDataDir/$file";
307 cmd($command, $verbose);
308 }else{
309 #print("Copying $icuDataDir/$item $tempDir/$icu4jDataDir/$file\n");
310 copy("$icuDataDir/$item", "$tempDir/$icu4jDataDir/$file");
311 }
312
313
314 }
315 chdir("..");
316 print "INFO: DONE\n";
317 }
318 #------------------------------------------------------------------------------------------------
319 sub cmd {
320 my $cmd = shift;
321 my $verbose = shift;
322 my $prompt = shift;
323
324 $prompt = "Command: $cmd.." unless ($prompt);
325 if(defined $verbose){
326 print $prompt."\n";
327 }
328 system($cmd);
329 my $exit_value = $? >> 8;
330 #my $signal_num = $? & 127;
331 #my $dumped_core = $? & 128;
332 if ($exit_value == 0) {
333 if(defined $verbose){
334 print "ok\n";
335 }
336 } else {
337 ++$errCount;
338 print "ERROR: Execution of $prompt returned ($exit_value)\n";
339 exit(1);
340 }
341 }
342 #-----------------------------------------------------------------------
343 sub usage {
344 print << "END";
345 Usage:
346 gendtjar.pl
347 Options:
348 --icu-root=<directory where icu4c lives>
349 --jar=<directory where jar.exe lives>
350 --icu4j-root=<directory>
351 --version=<ICU4C version>
352 --verbose
353 --help
354 e.g:
355 gendtjar.pl --icu-root=\\work\\icu --jar=\\jdk1.4.1\\bin --icu4j-root=\\work\\icu4j --version=3.0
356 END
357 exit(0);
358 }
359