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`;
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
()
98 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
101 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
105 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
109 $key = reg_find_key
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
110 $value = reg_get_value
($key);
114 my $dir = cygpath
(find_msvc
()->{'product_dir'}, 'w', $output_format);
115 $value = `/bin/find "$dir" -iname platformsdk | head -n 1`;
118 defined $value || die "Windows Sdk not found";
120 print cygpath
($value, 'w', $output_format);
125 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
126 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
131 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
132 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
135 my %msvs_express_2008 = (
137 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
138 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
141 my %msvc_express_2008 = (
143 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
144 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
149 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
150 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
151 'dll_suffix' => '100'
155 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
156 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
157 'dll_suffix' => '100'
162 my @ms_versions = ( \
%msvs_2008, \
%msvs_express_2008, \
%msvs_2010 );
164 for $ver (@ms_versions)
166 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
167 if (defined $install && $install ne '') {
168 $ver->{'product_dir'} = $install;
172 die "Can't find MS Visual Studio / VC++";
177 my @ms_versions = ( \
%msvc_2008, \
%msvc_express_2008, \
%msvc_2010 );
179 for $ver (@ms_versions)
181 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
182 if (defined $install && $install ne '') {
183 $ver->{'product_dir'} = $install;
187 die "Can't find MS Visual Studio / VC++";
192 my $ver = find_msvc
();
196 sub print_msvc_product_dir
()
198 my $ver = find_msvc
();
199 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
202 sub print_msvs_productdir
()
204 my $ver = find_msvs
();
205 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
208 sub print_csc_compiler_dir
()
210 my $dir = cygpath
(reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
211 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
212 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
213 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
214 print `dirname $csc_exe`;
217 sub print_dotnetsdk_dir
()
220 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
221 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
223 print cygpath
($dir, 'w', $output_format);
230 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
231 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
232 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
233 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
234 print cygpath
($dir, 'w', $output_format);
239 my ($src, $fname, $dest) = @_;
241 -f
"$src/$fname" || die "can't find $src";
242 -d
$dest || die "no directory $dest";
244 print STDERR
"Copying $src/$fname to $dest\n";
245 copy
("$src/$fname", $dest) || die "copy failed: $!";
246 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
249 sub msvc_find_version
($)
251 my $checkpath = shift;
252 my $ver = find_msvc
();
253 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
255 -d
$srcdir && return $ver;
257 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
259 -d
$srcdir && return $ver;
263 sub msvc_copy_dlls
($)
266 my $ver = msvc_find_version
('dll_path');
267 defined $ver || return;
268 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
271 copy_dll
($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
272 $dest . $ver->{'dll_suffix'});
273 copy_dll
($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
274 $dest . $ver->{'dll_suffix'});
275 if ($ver->{'dll_suffix'} == 90) {
276 copy_dll
($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
277 $dest . $ver->{'dll_suffix'});
278 copy_dll
($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
282 sub msvc_copy_msms
($$)
284 # $postfix is empty for x86, and '_x64' for x64
285 my ($dest, $postfix) = @_;
286 my $common_files_path = $ENV{"CommonProgramFiles(x86)"};
287 if (!defined $common_files_path) {
288 $common_files_path = $ENV{CommonProgramFiles
};
289 if (!defined $common_files_path) {
290 $common_files_path = "C:\\Program Files\\Common Files";
294 defined $common_files_path || die "Windows CommonProgramFiles not found";
296 my $msm_path = (cygpath
$common_files_path . "\\Merge Modules", 'w', $output_format);
297 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
298 print STDERR
"Copying $msm_path/$fname to $dest\n";
299 copy
("$msm_path/$fname", $dest) || die "copy failed: $!";
313 if ($opt eq '-w' || $opt eq '-u') {
314 $output_format = substr($opt, 1, 1);
316 push @commands, $opt;
321 $opt = shift @commands;
324 } elsif ($opt eq '--msvc-ver') {
326 } elsif ($opt eq '--msvc-copy-dlls') {
327 my $dest = shift @commands;
328 defined $dest || die "copy-dlls requires a destination directory";
329 msvc_copy_dlls
( $dest );
330 } elsif ($opt eq '--msvc-copy-msms') {
331 my $dest = shift @commands;
332 defined $dest || die "copy-msms requires a destination directory";
333 msvc_copy_msms
( $dest, '' );
334 } elsif ($opt eq '--msvc-copy-msms-64') {
335 my $dest = shift @commands;
336 defined $dest || die "copy-msms-64 requires a destination directory";
337 msvc_copy_msms
( $dest, '_x64' );
338 } elsif ($opt eq '--msvs-productdir') {
339 print_msvs_productdir
();
340 } elsif ($opt eq '--msvc-productdir') {
341 print_msvc_product_dir
();
342 } elsif ($opt eq '--dotnetsdk-dir') {
343 print_dotnetsdk_dir
();
344 } elsif ($opt eq '--csc-compilerdir') {
345 print_csc_compiler_dir
();
346 } elsif ($opt eq '--windows-sdk-home') {
347 print_windows_sdk_home
();
348 } elsif ($opt eq '--jdk-home') {
350 } elsif ($opt eq '--help' || $opt eq '/?') {
353 print "Unknown option '$opt'\n";