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-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
51 print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
52 print " --msvc-productdir - print productdir\n";
53 print " --msvs-productdir - print productdir\n";
54 print " --dotnetsdk-dir - print .NET SDK path\n";
55 print " --csc-compilerdir - print .NET SDK compiler path\n";
56 print " --windows-sdk-home - print Windows SDK install dir\n";
57 print " --jdk-home - print the jdk install dir\n";
58 print " --help - print this message\n";
63 my ($path, $input_format, $format) = @_;
65 return $path if ( ! defined $path );
66 # Strip trailing path separators
67 if ($input_format eq 'u') {
73 # 'Unterminated quoted string errors' from 'ash' when
74 # forking cygpath so - reimplement cygpath in perl [ gack ]
75 if ($format eq 'u' && $input_format eq 'w') {
77 $path =~ s
|([a
-zA
-Z
]):/|/cygdrive
/$1/|g
;
79 elsif ($format eq 'w' && $input_format eq 'u') {
80 $path =~ s
|/cygdrive/([a
-zA
-Z
])/|/$1/|g
;
89 my ($path, $unix) = @_;
91 $path = cygpath
($path, $unix, $output_format);
96 sub print_windows_sdk_home
()
100 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
102 if (!defined $value) {
103 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
106 if (!defined $value) {
107 $key = reg_find_key
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
108 $value = reg_get_value
($key);
111 defined $value || die "Windows SDK not found";
113 print cygpath
($value, 'w', $output_format);
118 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
119 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
124 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
125 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
128 my %msvs_express_2008 = (
130 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
131 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
134 my %msvc_express_2008 = (
136 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
137 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
142 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
143 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
144 'dll_suffix' => '100'
148 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
149 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
150 'dll_suffix' => '100'
155 my @ms_versions = ( \
%msvs_2008, \
%msvs_express_2008, \
%msvs_2010 );
157 for $ver (@ms_versions) {
158 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
159 if (defined $install && $install ne '') {
160 $ver->{'product_dir'} = $install;
164 die "Can't find MS Visual Studio / VC++";
169 my @ms_versions = ( \
%msvc_2008, \
%msvc_express_2008, \
%msvc_2010 );
171 for $ver (@ms_versions) {
172 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
173 if (defined $install && $install ne '') {
174 $ver->{'product_dir'} = $install;
178 die "Can't find MS Visual Studio / VC++";
183 my $ver = find_msvc
();
187 sub print_msvc_product_dir
()
189 my $ver = find_msvc
();
190 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
193 sub print_msvs_productdir
()
195 my $ver = find_msvs
();
196 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
199 sub print_csc_compiler_dir
()
201 my $dir = cygpath
(reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
202 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
203 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
204 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
205 print `dirname $csc_exe`;
208 sub print_dotnetsdk_dir
()
211 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
212 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
214 print cygpath
($dir, 'w', $output_format);
221 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
222 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
223 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
224 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
225 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
226 print cygpath
($dir, 'w', $output_format);
231 my ($src, $fname, $dest) = @_;
233 -f
"$src/$fname" || die "can't find $src";
234 -d
$dest || die "no directory $dest";
236 print STDERR
"Copying $src/$fname to $dest\n";
237 copy
("$src/$fname", $dest) || die "copy failed: $!";
238 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
241 sub msvc_find_version
($)
243 my $checkpath = shift;
244 my $ver = find_msvc
();
245 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
247 -d
$srcdir && return $ver;
249 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
251 -d
$srcdir && return $ver;
255 sub msvc_copy_dlls
($)
258 my $ver = msvc_find_version
('dll_path');
259 defined $ver || return;
260 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
263 copy_dll
($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
264 $dest . $ver->{'dll_suffix'});
265 copy_dll
($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
266 $dest . $ver->{'dll_suffix'});
267 if ($ver->{'dll_suffix'} == 90) {
268 copy_dll
($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
269 $dest . $ver->{'dll_suffix'});
270 copy_dll
($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
274 sub msvc_copy_msms
($$)
276 # $postfix is empty for x86, and '_x64' for x64
277 my ($dest, $postfix) = @_;
279 my $ver = find_msvc
();
280 (defined $ver && ($ver->{'ver'} eq '9.0')) || return;
282 my $msm_path = (cygpath reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/9.0/Setup/VS/MSMDir"), 'w', $output_format);
283 defined $msm_path || die "MSMDir not found";
284 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
285 print STDERR
"Copying $msm_path/$fname to $dest\n";
286 copy
("$msm_path/$fname", $dest) || die "copy failed: $!";
288 foreach $fname ("Microsoft_VC100_CRT_x86$postfix.msm") {
289 print STDERR
"Copying $msm_path/$fname to $dest\n";
290 copy
("$msm_path/$fname", $dest) || print "copy failed: $!";
304 if ($opt eq '-w' || $opt eq '-u') {
305 $output_format = substr($opt, 1, 1);
307 push @commands, $opt;
312 $opt = shift @commands;
315 } elsif ($opt eq '--msvc-ver') {
317 } elsif ($opt eq '--msvc-copy-dlls') {
318 my $dest = shift @commands;
319 defined $dest || die "copy-dlls requires a destination directory";
320 msvc_copy_dlls
( $dest );
321 } elsif ($opt eq '--msvc-copy-msms') {
322 my $dest = shift @commands;
323 defined $dest || die "copy-msms requires a destination directory";
324 msvc_copy_msms
( $dest, '' );
325 } elsif ($opt eq '--msvc-copy-msms-64') {
326 my $dest = shift @commands;
327 defined $dest || die "copy-msms-64 requires a destination directory";
328 msvc_copy_msms
( $dest, '_x64' );
329 } elsif ($opt eq '--msvs-productdir') {
330 print_msvs_productdir
();
331 } elsif ($opt eq '--msvc-productdir') {
332 print_msvc_product_dir
();
333 } elsif ($opt eq '--dotnetsdk-dir') {
334 print_dotnetsdk_dir
();
335 } elsif ($opt eq '--csc-compilerdir') {
336 print_csc_compiler_dir
();
337 } elsif ($opt eq '--windows-sdk-home') {
338 print_windows_sdk_home
();
339 } elsif ($opt eq '--jdk-home') {
341 } elsif ($opt eq '--help' || $opt eq '/?') {
344 print "Unknown option '$opt'\n";
350 # vim:set shiftwidth=4 softtabstop=4 expandtab: