Revert "new change in helpcontent2"
[LibreOffice.git] / oowintool
blobc81d81f56569e674eaef9c41cf712ffc07a331da
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-find-msms-vc100 - exit with 0 if Microsoft_VC100_CRT_x86.msm\n";
51 print " is available\n";
52 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
53 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
54 print " --msvc-productdir - print productdir\n";
55 print " --msvs-productdir - print productdir\n";
56 print " --dotnetsdk-dir - print .NET SDK path\n";
57 print " --csc-compilerdir - print .NET SDK compiler path\n";
58 print " --al-home - print AL.exe install dir\n";
59 print " --windows-sdk-home - print Windows SDK install dir\n";
60 print " --jdk-home - print the jdk install dir\n";
61 print " --help - print this message\n";
64 sub cygpath($$$)
66 my ($path, $input_format, $format) = @_;
68 return $path if ( ! defined $path );
69 # Strip trailing path separators
70 if ($input_format eq 'u') {
71 $path =~ s|/*\s*$||;
72 } else {
73 $path =~ s|\\*\s*$||;
76 # 'Unterminated quoted string errors' from 'ash' when
77 # forking cygpath so - reimplement cygpath in perl [ gack ]
78 if ($format eq 'u' && $input_format eq 'w') {
79 $path =~ s|\\|/|g;
80 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
82 elsif ($format eq 'w' && $input_format eq 'u') {
83 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
84 $path =~ s|/|\\|g;
87 return $path;
90 sub print_path($$)
92 my ($path, $unix) = @_;
94 $path = cygpath ($path, $unix, $output_format);
96 print $path;
99 sub print_windows_sdk_home()
101 my ($value, $key);
103 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows Kits/Installed Roots/KitsRoot');
105 if (!defined $value) {
106 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
108 if (!defined $value) {
109 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
113 if (!defined $value) {
114 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
115 $value = reg_get_value ($key);
118 defined $value || die "Windows SDK not found";
120 print cygpath ($value, 'w', $output_format);
123 sub print_al_home()
125 my ($value, $key);
127 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/*/WinSDK-NetFx40Tools/InstallationFolder');
128 $value = reg_get_value ($key);
130 print cygpath ($value, 'w', $output_format);
133 my %msvs_2008 = (
134 'ver' => '9.0',
135 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
136 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
137 'dll_suffix' => '90'
139 my %msvc_2008 = (
140 'ver' => '9.0',
141 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
142 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
143 'dll_suffix' => '90'
145 my %msvs_express_2008 = (
146 'ver' => '9.0',
147 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
148 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
149 'dll_suffix' => '90'
151 my %msvc_express_2008 = (
152 'ver' => '9.0',
153 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
154 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
155 'dll_suffix' => '90'
157 my %msvs_2010 = (
158 'ver' => '10.0',
159 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
160 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
161 'dll_suffix' => '100'
163 my %msvc_2010 = (
164 'ver' => '10.0',
165 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
166 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
167 'dll_suffix' => '100'
169 my %msvs_2012 = (
170 'ver' => '11.0',
171 'key' => 'Microsoft/VisualStudio/11.0/Setup/VS/ProductDir',
172 'dll_path' => 'VC/redist/x86/Microsoft.VC110.CRT',
173 'dll_suffix' => '110'
175 my %msvc_2012 = (
176 'ver' => '11.0',
177 'key' => 'Microsoft/VisualStudio/11.0/Setup/VC/ProductDir',
178 'dll_path' => 'redist/x86/Microsoft.VC110.CRT',
179 'dll_suffix' => '110'
182 sub find_msvs()
184 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2012, \%msvs_2010 );
186 for $ver (@ms_versions) {
187 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
188 if (defined $install && $install ne '') {
189 $ver->{'product_dir'} = $install;
190 return $ver;
193 die "Can't find MS Visual Studio / VC++";
196 sub find_msvc()
198 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2012, \%msvc_2010 );
200 for $ver (@ms_versions) {
201 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
202 if (defined $install && $install ne '') {
203 $ver->{'product_dir'} = $install;
204 return $ver;
207 die "Can't find MS Visual Studio / VC++";
210 sub print_msvc_ver()
212 my $ver = find_msvc();
213 print $ver->{'ver'};
216 sub print_msvc_product_dir()
218 my $ver = find_msvc();
219 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
222 sub print_msvs_productdir()
224 my $ver = find_msvs();
225 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
228 sub print_csc_compiler_dir()
230 my $csc_exe;
231 my $ver = find_msvc();
232 if ($ver->{'ver'} == "9.0") {
233 # We need to compile C# with the 3.5 or 2.0 compiler in order
234 # for the assemblies to be loadable by managed C++ code
235 # compiled with MSVC 2008.
236 $csc_exe =
237 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP/v3.5/InstallPath") ||
238 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot") . "v2.0.50727";
239 } else {
240 # Is it enough to look for the 4.0 compiler?
241 $csc_exe =
242 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP/v4/Client/InstallPath");
244 print cygpath ($csc_exe, 'w', $output_format);
247 sub print_dotnetsdk_dir()
249 my $dir =
250 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
251 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
252 if ($dir) {
253 print cygpath ($dir, 'w', $output_format);
257 sub print_jdk_dir()
259 my $dir =
260 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
261 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
262 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
263 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
264 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
265 print cygpath($dir, 'w', $output_format);
268 sub copy_dll($$$)
270 my ($src, $fname, $dest) = @_;
272 -f "$src/$fname" || die "can't find $src";
273 -d $dest || die "no directory $dest";
275 print STDERR "Copying $src/$fname to $dest\n";
276 copy ("$src/$fname", $dest) || die "copy failed: $!";
277 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
280 sub msvc_find_version($)
282 my $checkpath = shift;
283 my $ver = find_msvc();
284 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
285 $ver->{$checkpath});
286 -d $srcdir && return $ver;
287 $ver = find_msvs();
288 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
289 $ver->{$checkpath});
290 -d $srcdir && return $ver;
291 return undef;
294 sub msvc_copy_dlls($)
296 my $dest = shift;
297 my $ver = msvc_find_version('dll_path');
298 defined $ver || return;
299 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
300 $ver->{'dll_path'});
302 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
303 $dest . $ver->{'dll_suffix'});
304 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
305 $dest . $ver->{'dll_suffix'});
306 if ($ver->{'dll_suffix'} == 90) {
307 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
308 $dest . $ver->{'dll_suffix'});
309 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
313 sub msvc_find_msms()
315 my $ver = find_msvc();
316 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format) ||
317 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/10.0/Setup/VS/MSMDir"), 'w', $output_format) ||
318 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/11.0/Setup/VS/MSMDir"), 'w', $output_format);
319 defined $msm_path || die "MSMDir not found";
320 return -e "$msm_path/Microsoft_VC".$ver->{'dll_suffix'}."_CRT_x86.msm" ? 0 : 1;
323 sub msvc_copy_msms($$)
325 # $postfix is empty for x86, and '_x64' for x64
326 my ($dest, $postfix) = @_;
328 my $ver = find_msvc();
329 defined $ver || return;
331 my $msm_path = (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format) ||
332 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/10.0/Setup/VS/MSMDir"), 'w', $output_format) ||
333 (cygpath reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/11.0/Setup/VS/MSMDir"), 'w', $output_format);
334 defined $msm_path || die "MSMDir not found";
335 if ($ver->{'dll_suffix'} == 90) {
336 if ( $postfix eq "_x86" ) {
337 $postfix = ""
339 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
340 print STDERR "Copying $msm_path/$fname to $dest\n";
341 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
344 elsif ($ver->{'dll_suffix'} == 100) {
345 foreach $fname ("Microsoft_VC100_CRT$postfix.msm") {
346 print STDERR "Copying $msm_path/$fname to $dest\n";
347 copy ("$msm_path/$fname", $dest) || print "copy failed: $!\n";
350 else {
351 foreach $fname ("Microsoft_VC110_CRT$postfix.msm") {
352 print STDERR "Copying $msm_path/$fname to $dest\n";
353 copy ("$msm_path/$fname", $dest) || print "copy failed: $!\n";
358 if (!@ARGV) {
359 print_syntax();
360 exit 1;
363 my @commands = ();
364 my $opt;
365 while (@ARGV) {
366 $opt = shift @ARGV;
368 if ($opt eq '-w' || $opt eq '-u') {
369 $output_format = substr($opt, 1, 1);
370 } else {
371 push @commands, $opt;
375 while (@commands) {
376 $opt = shift @commands;
378 if (0) {
379 } elsif ($opt eq '--msvc-ver') {
380 print_msvc_ver();
381 } elsif ($opt eq '--msvc-copy-dlls') {
382 my $dest = shift @commands;
383 defined $dest || die "copy-dlls requires a destination directory";
384 msvc_copy_dlls( $dest );
385 } elsif ($opt eq '--msvc-find-msms') {
386 exit msvc_find_msms();
387 } elsif ($opt eq '--msvc-copy-msms') {
388 my $dest = shift @commands;
389 defined $dest || die "copy-msms requires a destination directory";
390 msvc_copy_msms( $dest, '_x86' );
391 } elsif ($opt eq '--msvc-copy-msms-64') {
392 my $dest = shift @commands;
393 defined $dest || die "copy-msms-64 requires a destination directory";
394 msvc_copy_msms( $dest, '_x64' );
395 } elsif ($opt eq '--msvs-productdir') {
396 print_msvs_productdir();
397 } elsif ($opt eq '--msvc-productdir') {
398 print_msvc_product_dir();
399 } elsif ($opt eq '--dotnetsdk-dir') {
400 print_dotnetsdk_dir();
401 } elsif ($opt eq '--csc-compilerdir') {
402 print_csc_compiler_dir();
403 } elsif ($opt eq '--windows-sdk-home') {
404 print_windows_sdk_home();
405 } elsif ($opt eq '--al-home') {
406 print_al_home();
407 } elsif ($opt eq '--jdk-home') {
408 print_jdk_dir();
409 } elsif ($opt eq '--help' || $opt eq '/?') {
410 print_syntax();
411 } else {
412 print "Unknown option '$opt'\n";
413 print_syntax();
414 exit 1;
418 # vim:set shiftwidth=4 softtabstop=4 expandtab: