1 #!/usr/bin/perl -w # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
5 my $output_format = 'u';
9 # it is believed that the registry moves keys around
10 # depending on OS version, this will de-mangle that
15 open ($fhandle, "/proc/registry/$key") || return;
16 # reg keys have 0x00 0x5c at the end
17 $value = (split /\0/, <$fhandle>)[0];
20 if ( defined $value ) {
23 # print "Value '$value' at '$key'\n";
31 # it is believed that the registry moves keys around
32 # depending on OS version, this will de-mangle that
35 $key = `cd /proc/registry/ ; ls $key 2>/dev/null`;
42 print "oowintool [option] ...\n";
43 print " encoding options\n";
44 print " -w - windows form\n";
45 print " -u - unix form (default)\n";
47 print " --msvc-ver - print version of MSVC eg. 6.0\n";
48 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
49 print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
50 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
51 print " --msvc-productdir - print productdir\n";
52 print " --msvs-productdir - print productdir\n";
53 print " --dotnetsdk-dir - print .NET SDK path\n";
54 print " --csc-compilerdir - print .NET SDK compiler path\n";
55 print " --windows-sdk-home - print Windows SDK install dir\n";
56 print " --jdk-home - print the jdk install dir\n";
57 print " --help - print this message\n";
62 my ($path, $input_format, $format) = @_;
64 return $path if ( ! defined $path );
65 # Strip trailing path separators
66 if ($input_format eq 'u') {
72 # 'Unterminated quoted string errors' from 'ash' when
73 # forking cygpath so - reimplement cygpath in perl [ gack ]
74 if ($format eq 'u' && $input_format eq 'w') {
76 $path =~ s
|([a
-zA
-Z
]):/|/cygdrive
/$1/|g
;
78 elsif ($format eq 'w' && $input_format eq 'u') {
79 $path =~ s
|/cygdrive/([a
-zA
-Z
])/|/$1/|g
;
88 my ($path, $unix) = @_;
90 $path = cygpath
($path, $unix, $output_format);
95 sub print_windows_sdk_home
()
99 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
101 if (!defined $value) {
102 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
105 if (!defined $value) {
106 $key = reg_find_key
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
107 $value = reg_get_value
($key);
110 defined $value || die "Windows SDK not found";
112 print cygpath
($value, 'w', $output_format);
117 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
118 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
123 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
124 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
127 my %msvs_express_2008 = (
129 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
130 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
133 my %msvc_express_2008 = (
135 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
136 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
141 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
142 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
143 'dll_suffix' => '100'
147 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
148 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
149 'dll_suffix' => '100'
154 my @ms_versions = ( \
%msvs_2008, \
%msvs_express_2008, \
%msvs_2010 );
156 for $ver (@ms_versions) {
157 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
158 if (defined $install && $install ne '') {
159 $ver->{'product_dir'} = $install;
163 die "Can't find MS Visual Studio / VC++";
168 my @ms_versions = ( \
%msvc_2008, \
%msvc_express_2008, \
%msvc_2010 );
170 for $ver (@ms_versions) {
171 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
172 if (defined $install && $install ne '') {
173 $ver->{'product_dir'} = $install;
177 die "Can't find MS Visual Studio / VC++";
182 my $ver = find_msvc
();
186 sub print_msvc_product_dir
()
188 my $ver = find_msvc
();
189 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
192 sub print_msvs_productdir
()
194 my $ver = find_msvs
();
195 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
198 sub print_csc_compiler_dir
()
200 my $dir = cygpath
(reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
201 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
202 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
203 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
204 print `dirname $csc_exe`;
207 sub print_dotnetsdk_dir
()
210 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
211 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
213 print cygpath
($dir, 'w', $output_format);
220 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
221 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
222 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
223 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
224 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
225 print cygpath
($dir, 'w', $output_format);
230 my ($src, $fname, $dest) = @_;
232 -f
"$src/$fname" || die "can't find $src";
233 -d
$dest || die "no directory $dest";
235 print STDERR
"Copying $src/$fname to $dest\n";
236 copy
("$src/$fname", $dest) || die "copy failed: $!";
237 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
240 sub msvc_find_version
($)
242 my $checkpath = shift;
243 my $ver = find_msvc
();
244 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
246 -d
$srcdir && return $ver;
248 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
250 -d
$srcdir && return $ver;
254 sub msvc_copy_dlls
($)
257 my $ver = msvc_find_version
('dll_path');
258 defined $ver || return;
259 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
262 copy_dll
($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
263 $dest . $ver->{'dll_suffix'});
264 copy_dll
($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
265 $dest . $ver->{'dll_suffix'});
266 if ($ver->{'dll_suffix'} == 90) {
267 copy_dll
($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
268 $dest . $ver->{'dll_suffix'});
269 copy_dll
($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
273 sub msvc_copy_msms
($$)
275 # $postfix is empty for x86, and '_x64' for x64
276 my ($dest, $postfix) = @_;
278 my $ver = find_msvc
();
279 (defined $ver && ($ver->{'ver'} eq '9.0')) || return;
281 my $msm_path = (cygpath reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format);
282 defined $msm_path || die "MSMDir not found";
283 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
284 print STDERR
"Copying $msm_path/$fname to $dest\n";
285 copy
("$msm_path/$fname", $dest) || die "copy failed: $!";
299 if ($opt eq '-w' || $opt eq '-u') {
300 $output_format = substr($opt, 1, 1);
302 push @commands, $opt;
307 $opt = shift @commands;
310 } elsif ($opt eq '--msvc-ver') {
312 } elsif ($opt eq '--msvc-copy-dlls') {
313 my $dest = shift @commands;
314 defined $dest || die "copy-dlls requires a destination directory";
315 msvc_copy_dlls
( $dest );
316 } elsif ($opt eq '--msvc-copy-msms') {
317 my $dest = shift @commands;
318 defined $dest || die "copy-msms requires a destination directory";
319 msvc_copy_msms
( $dest, '' );
320 } elsif ($opt eq '--msvc-copy-msms-64') {
321 my $dest = shift @commands;
322 defined $dest || die "copy-msms-64 requires a destination directory";
323 msvc_copy_msms
( $dest, '_x64' );
324 } elsif ($opt eq '--msvs-productdir') {
325 print_msvs_productdir
();
326 } elsif ($opt eq '--msvc-productdir') {
327 print_msvc_product_dir
();
328 } elsif ($opt eq '--dotnetsdk-dir') {
329 print_dotnetsdk_dir
();
330 } elsif ($opt eq '--csc-compilerdir') {
331 print_csc_compiler_dir
();
332 } elsif ($opt eq '--windows-sdk-home') {
333 print_windows_sdk_home
();
334 } elsif ($opt eq '--jdk-home') {
336 } elsif ($opt eq '--help' || $opt eq '/?') {
339 print "Unknown option '$opt'\n";
345 # vim:set shiftwidth=4 softtabstop=4 expandtab: