[mono] cli_ure-source-bootstrap-native_glue-cxx.diff: add mono support
[LibreOffice.git] / oowintool
blob26221f09c07ed7ead2e30099b43e666ea863a331
1 #!/usr/bin/perl -w
2 # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
4 use File::Copy;
5 use File::Glob;
7 my $output_format = 'u';
9 sub reg_get_value($)
11 # it is believed that the registry moves keys around
12 # depending on OS version, this will de-mangle that
13 my $key = shift;
14 my $fhandle;
15 my $value;
17 open ($fhandle, "/proc/registry/$key") || return;
18 # reg keys have 0x00 0x5c at the end
19 $value = (split /\0/, <$fhandle>)[0];
20 close ($fhandle);
22 if ( defined $value ) {
23 chomp ($value);
24 $value =~ s|\r\n||;
25 # print "Value '$value' at '$key'\n";
28 return $value;
31 sub print_syntax()
33 print "oowintool [option] ...\n";
34 print " encoding options\n";
35 print " -w - windows form\n";
36 print " -u - unix form (default)\n";
37 print " commands:\n";
38 print " --msvc-ver - print version of MSVC eg. 6.0\n";
39 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
40 print " --msvc-copy-dlls-64 <dest> - copy x64 msvc[pr]??.dlls into <dest>/msvcp??/\n";
41 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
42 print " --msvc-copy-msms-64 <ds> - copy the x64 mscrt merge modules to <ds>/msm90/\n";
43 print " --msvc-productdir - print productdir\n";
44 print " --msvs-productdir - print productdir\n";
45 print " --dotnetsdk-dir - print .NET SDK path\n";
46 print " --csc-compilerdir - print .NET SDK compiler path\n";
47 print " --al-home - print AL.exe install dir\n";
48 print " --windows-sdk-home - print Windows SDK install dir\n";
49 print " --jdk-home - print the jdk install dir\n";
50 print " --help - print this message\n";
53 sub cygpath($$$)
55 my ($path, $input_format, $format) = @_;
57 return $path if ( ! defined $path );
58 # Strip trailing path separators
59 if ($input_format eq 'u') {
60 $path =~ s|/*\s*$||;
61 } else {
62 $path =~ s|\\*\s*$||;
65 # 'Unterminated quoted string errors' from 'ash' when
66 # forking cygpath so - reimplement cygpath in perl [ gack ]
67 if ($format eq 'u' && $input_format eq 'w') {
68 $path =~ s|\\|/|g;
69 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
71 elsif ($format eq 'w' && $input_format eq 'u') {
72 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
73 $path =~ s|/|\\|g;
76 return $path;
79 sub print_path($$)
81 my ($path, $unix) = @_;
83 $path = cygpath ($path, $unix, $output_format);
85 print $path;
88 sub print_windows_sdk_home()
90 my ($value, $key);
92 # This is for the Windows SDK 8 distributed with MSVS 2012
93 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows Kits/Installed Roots/KitsRoot');
95 if (!defined $value) {
96 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
98 if (!defined $value) {
99 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
102 if (!defined $value) {
103 # Unclear whether we ever get here, don't the above match any
104 # recent Windows SDK?
105 foreach $key (File::Glob::bsd_glob('/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir')) {
106 $value = reg_get_value ($key);
107 last if defined $value;
111 defined $value || die "Windows SDK not found";
113 print cygpath ($value, 'w', $output_format);
116 sub print_al_home()
118 # Called by configure only if al.exe is not in the Windows SDK's
119 # bin folder, where it AFAIK always is in any recent Windows SDK,
120 # so whether this will ever be called is unclear...
122 my ($value, $key);
124 foreach $key (File::Glob::bsd_glob('/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/*/WinSDK-NetFx40Tools/InstallationFolder')) {
125 $key =~ s!^/proc/registry/!!;
126 $value = reg_get_value ($key);
128 # Sigh, the same test that configure does for al.exe
129 # being either directly in it, or in a "bin" subdir... But on
130 # the other hand we don't want to be mislead by a registry key
131 # that matches the above but points to a directory that does
132 # in fact not contain an al.exe. For me,
133 # HKLM/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.0A/WinSDK-NetFx40Tools/InstallationFolder
134 # contains
135 # c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
136 # but that then does not contain any al.exe.
138 if (-f "$value/bin/al.exe" || -f "$value/al.exe") {
139 print cygpath ($value, 'w', $output_format);
140 return;
143 die "Can't find al.exe";
146 my %msvs_2008 = (
147 'ver' => '9.0',
148 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
149 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
150 'dll_suffix' => '90'
152 my %msvc_2008 = (
153 'ver' => '9.0',
154 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
155 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
156 'dll_suffix' => '90'
158 my %msvs_express_2008 = (
159 'ver' => '9.0',
160 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
161 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
162 'dll_suffix' => '90'
164 my %msvc_express_2008 = (
165 'ver' => '9.0',
166 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
167 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
168 'dll_suffix' => '90'
170 my %msvs_2010 = (
171 'ver' => '10.0',
172 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
173 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
174 'dll_suffix' => '100'
176 my %msvc_2010 = (
177 'ver' => '10.0',
178 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
179 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
180 'dll_suffix' => '100'
182 my %msvs_2012 = (
183 'ver' => '11.0',
184 'key' => 'Microsoft/VisualStudio/11.0/Setup/VS/ProductDir',
185 'dll_path' => 'VC/redist/x86/Microsoft.VC110.CRT',
186 'dll_suffix' => '110'
188 my %msvc_2012 = (
189 'ver' => '11.0',
190 'key' => 'Microsoft/VisualStudio/11.0/Setup/VC/ProductDir',
191 'dll_path' => 'redist/x86/Microsoft.VC110.CRT',
192 'dll_suffix' => '110'
195 sub find_msvs()
197 my @ms_versions = ( \%msvs_2010, \%msvs_2012, \%msvs_2008, \%msvs_express_2008 );
199 for $ver (@ms_versions) {
200 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
201 if (defined $install && $install ne '') {
202 $ver->{'product_dir'} = $install;
203 return $ver;
206 die "Can't find MS Visual Studio / VC++";
209 sub find_msvc()
211 my @ms_versions = ( \%msvc_2010, \%msvc_2012, \%msvc_2008, \%msvc_express_2008 );
213 for $ver (@ms_versions) {
214 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
215 if (defined $install && $install ne '') {
216 $ver->{'product_dir'} = $install;
217 return $ver;
220 die "Can't find MS Visual Studio / VC++";
223 sub print_msvc_ver()
225 my $ver = find_msvc();
226 print $ver->{'ver'};
229 sub print_msvc_product_dir()
231 my $ver = find_msvc();
232 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
235 sub print_msvs_productdir()
237 my $ver = find_msvs();
238 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
241 sub print_csc_compiler_dir()
243 my $csc_exe;
244 my $ver = find_msvc();
245 if ($ver->{'ver'} == "9.0") {
246 # We need to compile C# with the 3.5 or 2.0 compiler in order
247 # for the assemblies to be loadable by managed C++ code
248 # compiled with MSVC 2008.
249 $csc_exe =
250 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP/v3.5/InstallPath") ||
251 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot") . "v2.0.50727";
252 } else {
253 # Is it enough to look for the 4.0 compiler?
254 $csc_exe =
255 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP/v4/Client/InstallPath");
257 print cygpath ($csc_exe, 'w', $output_format);
260 sub print_dotnetsdk_dir()
262 my $dir =
263 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
264 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
265 if ($dir) {
266 print cygpath ($dir, 'w', $output_format);
270 sub print_jdk_dir()
272 my $dir =
273 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
274 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
275 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
276 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
277 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
278 print cygpath($dir, 'w', $output_format);
281 sub copy_dll($$$)
283 my ($src, $fname, $dest) = @_;
285 -f "$src/$fname" || die "can't find $src";
286 -d $dest || die "no directory $dest";
288 print STDERR "Copying $src/$fname to $dest\n";
289 copy ("$src/$fname", $dest) || die "copy failed: $!";
290 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
293 sub msvc_find_version($)
295 my $checkpath = shift;
296 my $ver = find_msvc();
297 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
298 $ver->{$checkpath});
299 -d $srcdir && return $ver;
300 $ver = find_msvs();
301 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
302 $ver->{$checkpath});
303 -d $srcdir && return $ver;
304 return undef;
307 sub msvc_copy_dlls($$)
309 my $dest = shift;
310 my $arch = shift;
311 my $ver = msvc_find_version('dll_path');
312 defined $ver || return;
313 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
314 $ver->{'dll_path'});
316 $srcdir =~ s/x86/amd64/ if ($arch eq 'amd64');
318 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
319 $dest . $ver->{'dll_suffix'});
320 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
321 $dest . $ver->{'dll_suffix'});
322 if ($ver->{'dll_suffix'} == 90) {
323 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
324 $dest . $ver->{'dll_suffix'});
325 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
329 sub msvc_find_msms()
331 my $ver = find_msvc();
332 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format) ||
333 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/10.0/Setup/VS/MSMDir"), 'w', $output_format) ||
334 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/11.0/Setup/VS/MSMDir"), 'w', $output_format);
335 defined $msm_path || die "MSMDir not found";
336 return -e "$msm_path/Microsoft_VC".$ver->{'dll_suffix'}."_CRT_x86.msm" ? 0 : 1;
339 sub msvc_copy_msms($$)
341 # $postfix is empty for x86, and '_x64' for x64
342 my ($dest, $postfix) = @_;
344 my $ver = find_msvc();
345 defined $ver || return;
347 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format) ||
348 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/10.0/Setup/VS/MSMDir"), 'w', $output_format) ||
349 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/11.0/Setup/VS/MSMDir"), 'w', $output_format);
350 defined $msm_path || die "MSMDir not found";
351 if ($ver->{'dll_suffix'} == 90) {
352 if ( $postfix eq "_x86" ) {
353 $postfix = ""
355 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
356 print STDERR "Copying $msm_path/$fname to $dest\n";
357 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
360 elsif ($ver->{'dll_suffix'} == 100) {
361 foreach $fname ("Microsoft_VC100_CRT$postfix.msm") {
362 print STDERR "Copying $msm_path/$fname to $dest\n";
363 copy ("$msm_path/$fname", $dest) || print "copy failed: $!\n";
366 else {
367 foreach $fname ("Microsoft_VC110_CRT$postfix.msm") {
368 print STDERR "Copying $msm_path/$fname to $dest\n";
369 copy ("$msm_path/$fname", $dest) || print "copy failed: $!\n";
374 if (!@ARGV) {
375 print_syntax();
376 exit 1;
379 my @commands = ();
380 my $opt;
381 while (@ARGV) {
382 $opt = shift @ARGV;
384 if ($opt eq '-w' || $opt eq '-u') {
385 $output_format = substr($opt, 1, 1);
386 } else {
387 push @commands, $opt;
391 while (@commands) {
392 $opt = shift @commands;
394 if (0) {
395 } elsif ($opt eq '--msvc-ver') {
396 print_msvc_ver();
397 } elsif ($opt eq '--msvc-copy-dlls') {
398 my $dest = shift @commands;
399 defined $dest || die "copy-dlls requires a destination directory";
400 msvc_copy_dlls( $dest, 'x86' );
401 } elsif ($opt eq '--msvc-copy-dlls-64') {
402 my $dest = shift @commands;
403 defined $dest || die "copy-dlls requires a destination directory";
404 msvc_copy_dlls( $dest, 'amd64' );
405 } elsif ($opt eq '--msvc-find-msms') {
406 exit msvc_find_msms();
407 } elsif ($opt eq '--msvc-copy-msms') {
408 my $dest = shift @commands;
409 defined $dest || die "copy-msms requires a destination directory";
410 msvc_copy_msms( $dest, '_x86' );
411 } elsif ($opt eq '--msvc-copy-msms-64') {
412 my $dest = shift @commands;
413 defined $dest || die "copy-msms-64 requires a destination directory";
414 msvc_copy_msms( $dest, '_x64' );
415 } elsif ($opt eq '--msvs-productdir') {
416 print_msvs_productdir();
417 } elsif ($opt eq '--msvc-productdir') {
418 print_msvc_product_dir();
419 } elsif ($opt eq '--dotnetsdk-dir') {
420 print_dotnetsdk_dir();
421 } elsif ($opt eq '--csc-compilerdir') {
422 print_csc_compiler_dir();
423 } elsif ($opt eq '--windows-sdk-home') {
424 print_windows_sdk_home();
425 } elsif ($opt eq '--al-home') {
426 print_al_home();
427 } elsif ($opt eq '--jdk-home') {
428 print_jdk_dir();
429 } elsif ($opt eq '--help' || $opt eq '/?') {
430 print_syntax();
431 } else {
432 print "Unknown option '$opt'\n";
433 print_syntax();
434 exit 1;
438 # vim:set shiftwidth=4 softtabstop=4 expandtab: