Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / oowintool
blobd3117502d2ff1b15eefd4d6470dfd73c3c85c72d
1 #!/usr/bin/perl -w # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
3 use File::Copy;
5 my $output_format = 'u';
7 sub reg_get_value($)
9 # it is believed that the registry moves keys around
10 # depending on OS version, this will de-mangle that
11 my $key = shift;
12 my $fhandle;
13 my $value;
15 open ($fhandle, "/proc/registry/$key") || return;
16 # reg keys have 0x00 0x5c at the end
17 $value = (split /\0/, <$fhandle>)[0];
18 close ($fhandle);
20 if ( defined $value ) {
21 chomp ($value);
22 $value =~ s|\r\n||;
23 # print "Value '$value' at '$key'\n";
26 return $value;
29 sub reg_find_key($)
31 # it is believed that the registry moves keys around
32 # depending on OS version, this will de-mangle that
33 my $key = shift;
34 $key =~ s| |\\ |;
35 $key = `cd /proc/registry/ ; ls $key 2>/dev/null`;
37 return $key;
40 sub print_syntax()
42 print "oowintool [option] ...\n";
43 print " encoding options\n";
44 print " -w - windows form\n";
45 print " -u - unix form (default)\n";
46 print " commands:\n";
47 print " --msvc-ver - print version of MSVC eg. 6.0\n";
48 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
49 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
50 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
51 print " --msvc-productdir - print productdir\n";
52 print " --msvs-productdir - print productdir\n";
53 print " --dotnetsdk-dir - print .NET SDK path\n";
54 print " --csc-compilerdir - print .NET SDK compiler path\n";
55 print " --windows-sdk-home - print Windows SDK install dir\n";
56 print " --jdk-home - print the jdk install dir\n";
57 print " --help - print this message\n";
60 sub cygpath($$$)
62 my ($path, $input_format, $format) = @_;
64 return $path if ( ! defined $path );
65 # Strip trailing path separators
66 if ($input_format eq 'u') {
67 $path =~ s|/*\s*$||;
68 } else {
69 $path =~ s|\\*\s*$||;
72 # 'Unterminated quoted string errors' from 'ash' when
73 # forking cygpath so - reimplement cygpath in perl [ gack ]
74 if ($format eq 'u' && $input_format eq 'w') {
75 $path =~ s|\\|/|g;
76 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
78 elsif ($format eq 'w' && $input_format eq 'u') {
79 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
80 $path =~ s|/|\\|g;
83 return $path;
86 sub print_path($$)
88 my ($path, $unix) = @_;
90 $path = cygpath ($path, $unix, $output_format);
92 print $path;
95 sub print_windows_sdk_home()
97 my ($value, $key);
99 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
101 if (!defined $value) {
102 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
105 if (!defined $value) {
106 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
107 $value = reg_get_value ($key);
110 defined $value || die "Windows SDK not found";
112 print cygpath ($value, 'w', $output_format);
115 my %msvs_2008 = (
116 'ver' => '9.0',
117 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
118 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
119 'dll_suffix' => '90'
121 my %msvc_2008 = (
122 'ver' => '9.0',
123 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
124 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
125 'dll_suffix' => '90'
127 my %msvs_express_2008 = (
128 'ver' => '9.0',
129 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
130 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
131 'dll_suffix' => '90'
133 my %msvc_express_2008 = (
134 'ver' => '9.0',
135 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
136 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
137 'dll_suffix' => '90'
139 my %msvs_2010 = (
140 'ver' => '10.0',
141 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
142 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
143 'dll_suffix' => '100'
145 my %msvc_2010 = (
146 'ver' => '10.0',
147 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
148 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
149 'dll_suffix' => '100'
152 sub find_msvs()
154 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
156 for $ver (@ms_versions) {
157 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
158 if (defined $install && $install ne '') {
159 $ver->{'product_dir'} = $install;
160 return $ver;
163 die "Can't find MS Visual Studio / VC++";
166 sub find_msvc()
168 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
170 for $ver (@ms_versions) {
171 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
172 if (defined $install && $install ne '') {
173 $ver->{'product_dir'} = $install;
174 return $ver;
177 die "Can't find MS Visual Studio / VC++";
180 sub print_msvc_ver()
182 my $ver = find_msvc();
183 print $ver->{'ver'};
186 sub print_msvc_product_dir()
188 my $ver = find_msvc();
189 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
192 sub print_msvs_productdir()
194 my $ver = find_msvs();
195 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
198 sub print_csc_compiler_dir()
200 my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
201 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
202 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
203 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
204 print `dirname $csc_exe`;
207 sub print_dotnetsdk_dir()
209 my $dir =
210 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
211 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
212 if ($dir) {
213 print cygpath ($dir, 'w', $output_format);
217 sub print_jdk_dir()
219 my $dir =
220 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
221 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
222 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
223 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
224 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
225 print cygpath($dir, 'w', $output_format);
228 sub copy_dll($$$)
230 my ($src, $fname, $dest) = @_;
232 -f "$src/$fname" || die "can't find $src";
233 -d $dest || die "no directory $dest";
235 print STDERR "Copying $src/$fname to $dest\n";
236 copy ("$src/$fname", $dest) || die "copy failed: $!";
237 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
240 sub msvc_find_version($)
242 my $checkpath = shift;
243 my $ver = find_msvc();
244 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
245 $ver->{$checkpath});
246 -d $srcdir && return $ver;
247 $ver = find_msvs();
248 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
249 $ver->{$checkpath});
250 -d $srcdir && return $ver;
251 return undef;
254 sub msvc_copy_dlls($)
256 my $dest = shift;
257 my $ver = msvc_find_version('dll_path');
258 defined $ver || return;
259 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
260 $ver->{'dll_path'});
262 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
263 $dest . $ver->{'dll_suffix'});
264 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
265 $dest . $ver->{'dll_suffix'});
266 if ($ver->{'dll_suffix'} == 90) {
267 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
268 $dest . $ver->{'dll_suffix'});
269 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
273 sub msvc_copy_msms($$)
275 # $postfix is empty for x86, and '_x64' for x64
276 my ($dest, $postfix) = @_;
278 my $ver = find_msvc();
279 (defined $ver && ($ver->{'ver'} eq '9.0')) || return;
281 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format);
282 defined $msm_path || die "MSMDir not found";
283 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
284 print STDERR "Copying $msm_path/$fname to $dest\n";
285 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
289 if (!@ARGV) {
290 print_syntax();
291 exit 1;
294 my @commands = ();
295 my $opt;
296 while (@ARGV) {
297 $opt = shift @ARGV;
299 if ($opt eq '-w' || $opt eq '-u') {
300 $output_format = substr($opt, 1, 1);
301 } else {
302 push @commands, $opt;
306 while (@commands) {
307 $opt = shift @commands;
309 if (0) {
310 } elsif ($opt eq '--msvc-ver') {
311 print_msvc_ver();
312 } elsif ($opt eq '--msvc-copy-dlls') {
313 my $dest = shift @commands;
314 defined $dest || die "copy-dlls requires a destination directory";
315 msvc_copy_dlls( $dest );
316 } elsif ($opt eq '--msvc-copy-msms') {
317 my $dest = shift @commands;
318 defined $dest || die "copy-msms requires a destination directory";
319 msvc_copy_msms( $dest, '' );
320 } elsif ($opt eq '--msvc-copy-msms-64') {
321 my $dest = shift @commands;
322 defined $dest || die "copy-msms-64 requires a destination directory";
323 msvc_copy_msms( $dest, '_x64' );
324 } elsif ($opt eq '--msvs-productdir') {
325 print_msvs_productdir();
326 } elsif ($opt eq '--msvc-productdir') {
327 print_msvc_product_dir();
328 } elsif ($opt eq '--dotnetsdk-dir') {
329 print_dotnetsdk_dir();
330 } elsif ($opt eq '--csc-compilerdir') {
331 print_csc_compiler_dir();
332 } elsif ($opt eq '--windows-sdk-home') {
333 print_windows_sdk_home();
334 } elsif ($opt eq '--jdk-home') {
335 print_jdk_dir();
336 } elsif ($opt eq '--help' || $opt eq '/?') {
337 print_syntax();
338 } else {
339 print "Unknown option '$opt'\n";
340 print_syntax();
341 exit 1;
345 # vim:set shiftwidth=4 softtabstop=4 expandtab: