]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genrb/gendtjar.pl
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / tools / genrb / gendtjar.pl
1 #!/usr/bin/perl
2 # ********************************************************************
3 # * COPYRIGHT:
4 # * Copyright (c) 2002-2004, 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
26
27 main();
28
29 #------------------------------------------------------------------
30 sub main(){
31
32 GetOptions(
33 "--icu-root=s" => \$icuRootDir,
34 "--jar=s" => \$jarDir,
35 "--icu4j-root=s" => \$icu4jDir,
36 "--version=s" => \$version
37 );
38 usage() unless defined $icuRootDir;
39 usage() unless defined $jarDir;
40 #usage() unless defined $icu4jRootDir;
41 $icuswap = $icuRootDir."/bin/icuswap -tb";
42 $tempDir =cwd();
43 $tempDir .= "/temp";
44 $version =~ s/\.//;
45 $icu4jDataDir ="com/ibm/icu/impl/data/icudt".$version."b";
46 $icu4jTestDataDir = "com/ibm/icu/dev/data/testdata";
47 $icuDataDir =$icuRootDir."/source/data/out/build/icudt".$version.checkPlatform();
48 $icuTestDataDir =$icuRootDir."/source/test/testdata/out/build/";
49 convertData($icuDataDir, $icuswap, $tempDir, $icu4jDataDir);
50 #convertData($icuDataDir."/coll/", $icuswap, $tempDir, $icu4jDataDir."/coll");
51 createJar("$jarDir/jar", "icudata.jar", $tempDir, $icu4jDataDir);
52
53 convertTestData($icuTestDataDir, $icuswap, $tempDir, $icu4jTestDataDir);
54 createJar("$jarDir/jar", "testdata.jar", $tempDir, $icu4jTestDataDir);
55 }
56
57 #-----------------------------------------------------------------------
58 sub createJar{
59 local($jar, $jarFile, $tempDir, $dirToJar) = @_;
60 chdir($tempDir);
61 $command = "$jar cvf $jarFile -C $tempDir $dirToJar";
62 cmd($command);
63 }
64 #-----------------------------------------------------------------------
65 sub checkPlatform {
66 my $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/;
67 if ($is_big_endian) {
68 return "b";
69 }else{
70 return "l";
71 }
72 }
73 #-----------------------------------------------------------------------
74
75 #-----------------------------------------------------------------------
76 sub convertData{
77 local($icuDataDir, $icuswap, $tempDir, $icu4jDataDir) =@_;
78 my $dir = $tempDir."/".$icu4jDataDir;
79 # create the temp directory
80 mkpath("$tempDir/$icu4jDataDir");
81 # cd to the temp directory
82 chdir($tempDir);
83
84 my @list;
85 opendir(DIR,$icuDataDir);
86 print $icuDataDir;
87 @list = readdir(DIR);
88 closedir(DIR);
89 print "{Command: $op*.*}\n";
90 my $op = $icuswap;
91 $i=0;
92 # now convert
93 foreach $item (@list){
94 next if($item eq "." || $item eq "..");
95 next if($item =~ /^t_.*$\.res/ ||$item =~ /^translit_.*$\.res/ || $item =~ /$\.cnv/ ||
96 $item=~/$\.crs/ || $item=~ /$\.txt/ || $item=~ /^zoneinfo/ ||
97 $item=~/icudata\.res/ || $item=~/$\.exp/ || $item=~/$\.lib/ || $item=~/$\.obj/ ||
98 $item=~/cnvalias\.icu/ || $item=~/$\.lst/);
99 if(-d "$icuDataDir/$item"){
100 convertData("$icuDataDir/$item/", $icuswap, $tempDir, "$icu4jDataDir./$item/");
101 next;
102 }
103 $command = $icuswap." $icuDataDir/$item $tempDir/$icu4jDataDir/$item";
104 cmd($command);
105
106 }
107 chdir("..");
108 print "\nDONE\n";
109 }
110 #-----------------------------------------------------------------------
111 sub convertTestData{
112 local($icuDataDir, $icuswap, $tempDir, $icu4jDataDir) =@_;
113 my $dir = $tempDir."/".$icu4jDataDir;
114 # create the temp directory
115 mkpath("$tempDir/$icu4jDataDir");
116 # cd to the temp directory
117 chdir($tempDir);
118 print "{Command: $op*.*}\n";
119 my $op = $icuswap;
120 my @list;
121 opendir(DIR,$icuDataDir);
122 print $icuDataDir;
123 @list = readdir(DIR);
124 closedir(DIR);
125
126 $i=0;
127 # now convert
128 foreach $item (@list){
129 next if($item eq "." || $item eq "..");
130 next if($item =~ /$\.cnv/ || item=~/$\.crs/ || $item=~ /$\.txt/ ||
131 $item=~/$\.exp/ || $item=~/$\.lib/ || $item=~/$\.obj/ ||
132 $item=~/$\.mak/ || $item=~/test\.icu/ || $item=~/$\.lst/);
133
134 if($item =~ /^testdata_/){
135 $file = $item;
136 $file =~ s/testdata_//g;
137 $command = "$icuswap $icuDataDir/$item $tempDir/$icu4jDataDir/$file";
138 cmd($command);
139 }
140
141 }
142 chdir("..");
143 print "\nDONE\n";
144 }
145 #------------------------------------------------------------------------------------------------
146 sub cmd {
147 my $cmd = shift;
148 my $prompt = shift;
149 $prompt = "Command: $cmd.." unless ($prompt);
150 print $prompt."\n";
151 system($cmd);
152 my $exit_value = $? >> 8;
153 #my $signal_num = $? & 127;
154 #my $dumped_core = $? & 128;
155 if ($exit_value == 0) {
156 print "ok\n";
157 } else {
158 ++$errCount;
159 print "ERROR ($exit_value)\n";
160 exit(1);
161 }
162 }
163 #-----------------------------------------------------------------------
164 sub usage {
165 print << "END";
166 Usage:
167 gendtjar.pl
168 Options:
169 --icu-root=<directory where icu4c lives>
170 --jar=<directory where jar.exe lives>
171 --icu4j-root=<directory>
172 --version=<ICU4C version>
173 e.g:
174 gendtjar.pl --icu-root=\\work\\icu --jar=\\jdk1.4.1\\bin --icu4j-root=\\work\\icu4j --version=3.0
175 END
176 exit(0);
177 }
178