Bump for 3.6-28
[LibreOffice.git] / oowintool
blob087d478d3bff80c798874093abfc9bc3aa46bae1
1 #!/usr/bin/perl -w
2 # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
4 use File::Copy;
6 my $output_format = 'u';
8 sub reg_get_value($)
10 # it is believed that the registry moves keys around
11 # depending on OS version, this will de-mangle that
12 my $key = shift;
13 my $fhandle;
14 my $value;
16 open ($fhandle, "/proc/registry/$key") || return;
17 # reg keys have 0x00 0x5c at the end
18 $value = (split /\0/, <$fhandle>)[0];
19 close ($fhandle);
21 if ( defined $value ) {
22 chomp ($value);
23 $value =~ s|\r\n||;
24 # print "Value '$value' at '$key'\n";
27 return $value;
30 sub reg_find_key($)
32 # it is believed that the registry moves keys around
33 # depending on OS version, this will de-mangle that
34 my $key = shift;
35 $key =~ s| |\\ |;
36 $key = `cd /proc/registry/ ; ls $key 2>/dev/null`;
38 return $key;
41 sub print_syntax()
43 print "oowintool [option] ...\n";
44 print " encoding options\n";
45 print " -w - windows form\n";
46 print " -u - unix form (default)\n";
47 print " commands:\n";
48 print " --msvc-ver - print version of MSVC eg. 6.0\n";
49 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
50 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
51 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
52 print " --msvc-productdir - print productdir\n";
53 print " --msvs-productdir - print productdir\n";
54 print " --dotnetsdk-dir - print .NET SDK path\n";
55 print " --csc-compilerdir - print .NET SDK compiler path\n";
56 print " --windows-sdk-home - print Windows SDK install dir\n";
57 print " --jdk-home - print the jdk install dir\n";
58 print " --help - print this message\n";
61 sub cygpath($$$)
63 my ($path, $input_format, $format) = @_;
65 return $path if ( ! defined $path );
66 # Strip trailing path separators
67 if ($input_format eq 'u') {
68 $path =~ s|/*\s*$||;
69 } else {
70 $path =~ s|\\*\s*$||;
73 # 'Unterminated quoted string errors' from 'ash' when
74 # forking cygpath so - reimplement cygpath in perl [ gack ]
75 if ($format eq 'u' && $input_format eq 'w') {
76 $path =~ s|\\|/|g;
77 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
79 elsif ($format eq 'w' && $input_format eq 'u') {
80 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
81 $path =~ s|/|\\|g;
84 return $path;
87 sub print_path($$)
89 my ($path, $unix) = @_;
91 $path = cygpath ($path, $unix, $output_format);
93 print $path;
96 sub print_windows_sdk_home()
98 my ($value, $key);
100 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
102 if (!defined $value) {
103 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
106 if (!defined $value) {
107 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
108 $value = reg_get_value ($key);
111 defined $value || die "Windows SDK not found";
113 print cygpath ($value, 'w', $output_format);
116 my %msvs_2008 = (
117 'ver' => '9.0',
118 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
119 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
120 'dll_suffix' => '90'
122 my %msvc_2008 = (
123 'ver' => '9.0',
124 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
125 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
126 'dll_suffix' => '90'
128 my %msvs_express_2008 = (
129 'ver' => '9.0',
130 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
131 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
132 'dll_suffix' => '90'
134 my %msvc_express_2008 = (
135 'ver' => '9.0',
136 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
137 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
138 'dll_suffix' => '90'
140 my %msvs_2010 = (
141 'ver' => '10.0',
142 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
143 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
144 'dll_suffix' => '100'
146 my %msvc_2010 = (
147 'ver' => '10.0',
148 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
149 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
150 'dll_suffix' => '100'
153 sub find_msvs()
155 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
157 for $ver (@ms_versions) {
158 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
159 if (defined $install && $install ne '') {
160 $ver->{'product_dir'} = $install;
161 return $ver;
164 die "Can't find MS Visual Studio / VC++";
167 sub find_msvc()
169 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
171 for $ver (@ms_versions) {
172 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
173 if (defined $install && $install ne '') {
174 $ver->{'product_dir'} = $install;
175 return $ver;
178 die "Can't find MS Visual Studio / VC++";
181 sub print_msvc_ver()
183 my $ver = find_msvc();
184 print $ver->{'ver'};
187 sub print_msvc_product_dir()
189 my $ver = find_msvc();
190 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
193 sub print_msvs_productdir()
195 my $ver = find_msvs();
196 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
199 sub print_csc_compiler_dir()
201 my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
202 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
203 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
204 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
205 print `dirname $csc_exe`;
208 sub print_dotnetsdk_dir()
210 my $dir =
211 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
212 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
213 if ($dir) {
214 print cygpath ($dir, 'w', $output_format);
218 sub print_jdk_dir()
220 my $dir =
221 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
222 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
223 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
224 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
225 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
226 print cygpath($dir, 'w', $output_format);
229 sub copy_dll($$$)
231 my ($src, $fname, $dest) = @_;
233 -f "$src/$fname" || die "can't find $src";
234 -d $dest || die "no directory $dest";
236 print STDERR "Copying $src/$fname to $dest\n";
237 copy ("$src/$fname", $dest) || die "copy failed: $!";
238 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
241 sub msvc_find_version($)
243 my $checkpath = shift;
244 my $ver = find_msvc();
245 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
246 $ver->{$checkpath});
247 -d $srcdir && return $ver;
248 $ver = find_msvs();
249 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
250 $ver->{$checkpath});
251 -d $srcdir && return $ver;
252 return undef;
255 sub msvc_copy_dlls($)
257 my $dest = shift;
258 my $ver = msvc_find_version('dll_path');
259 defined $ver || return;
260 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
261 $ver->{'dll_path'});
263 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
264 $dest . $ver->{'dll_suffix'});
265 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
266 $dest . $ver->{'dll_suffix'});
267 if ($ver->{'dll_suffix'} == 90) {
268 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
269 $dest . $ver->{'dll_suffix'});
270 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
274 sub msvc_copy_msms($$)
276 # $postfix is empty for x86, and '_x64' for x64
277 my ($dest, $postfix) = @_;
279 my $ver = find_msvc();
280 (defined $ver && ($ver->{'ver'} eq '9.0')) || return;
282 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format);
283 defined $msm_path || die "MSMDir not found";
284 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
285 print STDERR "Copying $msm_path/$fname to $dest\n";
286 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
288 foreach $fname ("Microsoft_VC100_CRT_x86$postfix.msm") {
289 print STDERR "Copying $msm_path/$fname to $dest\n";
290 copy ("$msm_path/$fname", $dest) || print "copy failed: $!";
294 if (!@ARGV) {
295 print_syntax();
296 exit 1;
299 my @commands = ();
300 my $opt;
301 while (@ARGV) {
302 $opt = shift @ARGV;
304 if ($opt eq '-w' || $opt eq '-u') {
305 $output_format = substr($opt, 1, 1);
306 } else {
307 push @commands, $opt;
311 while (@commands) {
312 $opt = shift @commands;
314 if (0) {
315 } elsif ($opt eq '--msvc-ver') {
316 print_msvc_ver();
317 } elsif ($opt eq '--msvc-copy-dlls') {
318 my $dest = shift @commands;
319 defined $dest || die "copy-dlls requires a destination directory";
320 msvc_copy_dlls( $dest );
321 } elsif ($opt eq '--msvc-copy-msms') {
322 my $dest = shift @commands;
323 defined $dest || die "copy-msms requires a destination directory";
324 msvc_copy_msms( $dest, '' );
325 } elsif ($opt eq '--msvc-copy-msms-64') {
326 my $dest = shift @commands;
327 defined $dest || die "copy-msms-64 requires a destination directory";
328 msvc_copy_msms( $dest, '_x64' );
329 } elsif ($opt eq '--msvs-productdir') {
330 print_msvs_productdir();
331 } elsif ($opt eq '--msvc-productdir') {
332 print_msvc_product_dir();
333 } elsif ($opt eq '--dotnetsdk-dir') {
334 print_dotnetsdk_dir();
335 } elsif ($opt eq '--csc-compilerdir') {
336 print_csc_compiler_dir();
337 } elsif ($opt eq '--windows-sdk-home') {
338 print_windows_sdk_home();
339 } elsif ($opt eq '--jdk-home') {
340 print_jdk_dir();
341 } elsif ($opt eq '--help' || $opt eq '/?') {
342 print_syntax();
343 } else {
344 print "Unknown option '$opt'\n";
345 print_syntax();
346 exit 1;
350 # vim:set shiftwidth=4 softtabstop=4 expandtab: