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-productdir - print productdir\n";
50 print " --msvs-productdir - print productdir\n";
51 print " --dotnetsdk-dir - print .NET SDK path\n";
52 print " --csc-compilerdir - print .NET SDK compiler path\n";
53 print " --windows-sdk-home - print Windows SDK install dir\n";
54 print " --jdk-home - print the jdk install dir\n";
55 print " --nsis-dir - print NSIS path\n";
56 print " --help - print this message\n";
61 my ($path, $input_format, $format) = @_;
63 return $path if ( ! defined $path );
64 # Strip trailing path separators
65 if ($input_format eq 'u') {
71 # 'Unterminated quoted string errors' from 'ash' when
72 # forking cygpath so - reimplement cygpath in perl [ gack ]
73 if ($format eq 'u' && $input_format eq 'w') {
75 $path =~ s
|([a
-zA
-Z
]):/|/cygdrive
/$1/|g
;
77 elsif ($format eq 'w' && $input_format eq 'u') {
78 $path =~ s
|/cygdrive/([a
-zA
-Z
])/|/$1/|g
;
87 my ($path, $unix) = @_;
89 $path = cygpath
($path, $unix, $output_format);
94 sub print_windows_sdk_home
()
97 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
100 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
104 $value = reg_get_value
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
108 $key = reg_find_key
('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
109 $value = reg_get_value
($key);
113 my $dir = cygpath
(find_msvc
()->{'product_dir'}, 'w', $output_format);
114 $value = `/bin/find "$dir" -iname platformsdk | head -n 1`;
117 defined $value || die "Windows Sdk not found";
119 print cygpath
($value, 'w', $output_format);
124 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
125 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
130 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
131 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
134 my %msvs_express_2008 = (
136 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
137 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
140 my %msvc_express_2008 = (
142 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
143 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
148 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
149 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
150 'dll_suffix' => '100'
154 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
155 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
156 'dll_suffix' => '100'
161 my @ms_versions = ( \
%msvs_2008, \
%msvs_express_2008, \
%msvs_2010 );
163 for $ver (@ms_versions)
165 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
166 if (defined $install && $install ne '') {
167 $ver->{'product_dir'} = $install;
171 die "Can't find MS Visual Studio / VC++";
176 my @ms_versions = ( \
%msvc_2008, \
%msvc_express_2008, \
%msvc_2010 );
178 for $ver (@ms_versions)
180 my $install = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
181 if (defined $install && $install ne '') {
182 $ver->{'product_dir'} = $install;
186 die "Can't find MS Visual Studio / VC++";
191 my $ver = find_msvc
();
195 sub print_msvc_product_dir
()
197 my $ver = find_msvc
();
198 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
201 sub print_msvs_productdir
()
203 my $ver = find_msvs
();
204 print cygpath
($ver->{'product_dir'}, 'w', $output_format);
207 sub print_csc_compiler_dir
()
209 my $dir = cygpath
(reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
210 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
211 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
212 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
213 print `dirname $csc_exe`;
216 sub print_dotnetsdk_dir
()
219 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
220 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
222 print cygpath
($dir, 'w', $output_format);
229 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
230 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
231 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
232 reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
233 print cygpath
($dir, 'w', $output_format);
238 my $dir = reg_get_value
("HKEY_LOCAL_MACHINE/SOFTWARE/NSIS/@");
239 print cygpath
($dir, 'w', $output_format) if defined $dir;
244 my ($src, $fname, $dest) = @_;
246 -f
"$src/$fname" || die "can't find $src";
247 -d
$dest || die "no directory $dest";
249 print STDERR
"Copying $src/$fname to $dest\n";
250 copy
("$src/$fname", $dest) || die "copy failed: $!";
251 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
254 sub msvc_find_version
($)
256 my $checkpath = shift;
257 my $ver = find_msvc
();
258 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
260 -d
$srcdir && return $ver;
262 $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
264 -d
$srcdir && return $ver;
268 sub msvc_copy_dlls
($)
271 my $ver = msvc_find_version
('dll_path');
272 defined $ver || return;
273 my $srcdir = (cygpath
($ver->{'product_dir'}, 'w', 'u') . '/' .
276 copy_dll
($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
277 $dest . $ver->{'dll_suffix'});
278 copy_dll
($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
279 $dest . $ver->{'dll_suffix'});
280 if ($ver->{'dll_suffix'} == 90) {
281 copy_dll
($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
282 $dest . $ver->{'dll_suffix'});
283 copy_dll
($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
297 if ($opt eq '-w' || $opt eq '-u') {
298 $output_format = substr($opt, 1, 1);
300 push @commands, $opt;
305 $opt = shift @commands;
308 } elsif ($opt eq '--msvc-ver') {
310 } elsif ($opt eq '--msvc-copy-dlls') {
311 my $dest = shift @commands;
312 defined $dest || die "copy-dlls requires a destination directory";
313 msvc_copy_dlls
( $dest );
314 } elsif ($opt eq '--msvs-productdir') {
315 print_msvs_productdir
();
316 } elsif ($opt eq '--msvc-productdir') {
317 print_msvc_product_dir
();
318 } elsif ($opt eq '--dotnetsdk-dir') {
319 print_dotnetsdk_dir
();
320 } elsif ($opt eq '--csc-compilerdir') {
321 print_csc_compiler_dir
();
322 } elsif ($opt eq '--windows-sdk-home') {
323 print_windows_sdk_home
();
324 } elsif ($opt eq '--jdk-home') {
326 } elsif ($opt eq '--nsis-dir') {
328 } elsif ($opt eq '--help' || $opt eq '/?') {
331 print "Unknown option '$opt'\n";