2 # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
6 my $output_format = 'u';
10 # it is believed that the registry moves keys around
11 # depending on OS version, this will de-mangle that
16 open ($fhandle, "/proc/registry/$key") || return;
17 # reg keys have 0x00 0x5c at the end
18 $value = (split /\0/, <$fhandle>)[0];
21 if ( defined $value ) {
24 # print "Value '$value' at '$key'\n";
32 # it is believed that the registry moves keys around
33 # depending on OS version, this will de-mangle that
36 $key = `cd /proc/registry/ ; ls $key 2>/dev/null`;
43 print "oowintool [option] ...\n";
44 print " encoding options\n";
45 print " -w - windows form\n";
46 print " -u - unix form (default)\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";
66 my ($path, $input_format, $format) = @_;
68 return $path if ( ! defined $path );
69 # Strip trailing path separators
70 if ($input_format eq 'u') {
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') {
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
;
92 my ($path, $unix) = @_;
94 $path = cygpath
($path, $unix, $output_format);
99 sub print_windows_sdk_home
()
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);
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);
135 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
136 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
141 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
142 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
145 my %msvs_express_2008 = (
147 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
148 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
151 my %msvc_express_2008 = (
153 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
154 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
159 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
160 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
161 'dll_suffix' => '100'
165 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
166 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
167 'dll_suffix' => '100'
171 'key' => 'Microsoft/VisualStudio/11.0/Setup/VS/ProductDir',
172 'dll_path' => 'VC/redist/x86/Microsoft.VC110.CRT',
173 'dll_suffix' => '110'
177 'key' => 'Microsoft/VisualStudio/11.0/Setup/VC/ProductDir',
178 'dll_path' => 'redist/x86/Microsoft.VC110.CRT',
179 'dll_suffix' => '110'
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;
193 die "Can't find MS Visual Studio / VC++";
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;
207 die "Can't find MS Visual Studio / VC++";
212 my $ver = find_msvc
();
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
()
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.
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";
240 # Is it enough to look for the 4.0 compiler?
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
()
250 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
251 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
253 print cygpath
($dir, 'w', $output_format);
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);
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') . '/' .
286 -d
$srcdir && return $ver;
288 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
290 -d
$srcdir && return $ver;
294 sub msvc_copy_dlls
($)
297 my $ver = msvc_find_version
('dll_path');
298 defined $ver || return;
299 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
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'});
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" ) {
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";
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";
368 if ($opt eq '-w' || $opt eq '-u') {
369 $output_format = substr($opt, 1, 1);
371 push @commands, $opt;
376 $opt = shift @commands;
379 } elsif ($opt eq '--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') {
407 } elsif ($opt eq '--jdk-home') {
409 } elsif ($opt eq '--help' || $opt eq '/?') {
412 print "Unknown option '$opt'\n";
418 # vim:set shiftwidth=4 softtabstop=4 expandtab: