2 # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
7 my $output_format = 'u';
11 # it is believed that the registry moves keys around
12 # depending on OS version, this will de-mangle that
17 open ($fhandle, "/proc/registry/$key") || return;
18 # reg keys have 0x00 0x5c at the end
19 $value = (split /\0/, <$fhandle>)[0];
22 if ( defined $value ) {
25 # print "Value '$value' at '$key'\n";
33 print "oowintool [option] ...\n";
34 print " encoding options\n";
35 print " -w - windows form\n";
36 print " -u - unix form (default)\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";
55 my ($path, $input_format, $format) = @_;
57 return $path if ( ! defined $path );
58 # Strip trailing path separators
59 if ($input_format eq 'u') {
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') {
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
;
81 my ($path, $unix) = @_;
83 $path = cygpath
($path, $unix, $output_format);
88 sub print_windows_sdk_home
()
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);
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...
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
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);
143 die "Can't find al.exe";
148 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
149 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
154 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
155 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
158 my %msvs_express_2008 = (
160 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
161 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
164 my %msvc_express_2008 = (
166 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
167 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
172 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
173 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
174 'dll_suffix' => '100'
178 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
179 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
180 'dll_suffix' => '100'
184 'key' => 'Microsoft/VisualStudio/11.0/Setup/VS/ProductDir',
185 'dll_path' => 'VC/redist/x86/Microsoft.VC110.CRT',
186 'dll_suffix' => '110'
190 'key' => 'Microsoft/VisualStudio/11.0/Setup/VC/ProductDir',
191 'dll_path' => 'redist/x86/Microsoft.VC110.CRT',
192 'dll_suffix' => '110'
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;
206 die "Can't find MS Visual Studio / VC++";
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;
220 die "Can't find MS Visual Studio / VC++";
225 my $ver = find_msvc
();
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
()
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.
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";
253 # Is it enough to look for the 4.0 compiler?
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
()
263 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
264 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
266 print cygpath
($dir, 'w', $output_format);
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);
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') . '/' .
299 -d
$srcdir && return $ver;
301 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
303 -d
$srcdir && return $ver;
307 sub msvc_copy_dlls
($$)
311 my $ver = msvc_find_version
('dll_path');
312 defined $ver || return;
313 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
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'});
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" ) {
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";
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";
384 if ($opt eq '-w' || $opt eq '-u') {
385 $output_format = substr($opt, 1, 1);
387 push @commands, $opt;
392 $opt = shift @commands;
395 } elsif ($opt eq '--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') {
427 } elsif ($opt eq '--jdk-home') {
429 } elsif ($opt eq '--help' || $opt eq '/?') {
432 print "Unknown option '$opt'\n";
438 # vim:set shiftwidth=4 softtabstop=4 expandtab: