blob: ce55e888c467b7f48dc7395629e6c656375957cb [file] [log] [blame]
Tor Lillqvistdcc90962012-03-09 10:35:20 +02001#!/usr/bin/perl -w # -*- tab-width: 4; cperl-indent-level: 4; indent-tabs-mode: nil -*-
Rüdiger Timme35fbf72006-05-05 07:11:16 +00002
3use File::Copy;
4
5my $output_format = 'u';
6
7sub reg_get_value($)
8{
9 # it is believed that the registry moves keys around
10 # depending on OS version, this will de-mangle that
11 my $key = shift;
12 my $fhandle;
13 my $value;
14
15 open ($fhandle, "/proc/registry/$key") || return;
16 # reg keys have 0x00 0x5c at the end
17 $value = (split /\0/, <$fhandle>)[0];
18 close ($fhandle);
19
Jens-Heiner Rechtien84155952007-06-27 16:51:45 +000020 if ( defined $value ) {
21 chomp ($value);
22 $value =~ s|\r\n||;
Tor Lillqvistdcc90962012-03-09 10:35:20 +020023 # print "Value '$value' at '$key'\n";
Jens-Heiner Rechtien84155952007-06-27 16:51:45 +000024 }
Rüdiger Timme35fbf72006-05-05 07:11:16 +000025
26 return $value;
27}
28
29sub reg_find_key($)
30{
31 # it is believed that the registry moves keys around
32 # depending on OS version, this will de-mangle that
33 my $key = shift;
34 $key =~ s| |\\ |;
Tor Lillqvist2a2c05e2012-03-09 10:22:44 +020035 $key = `cd /proc/registry/ ; ls $key 2>/dev/null`;
Rüdiger Timme35fbf72006-05-05 07:11:16 +000036
37 return $key;
38}
39
40sub print_syntax()
41{
42 print "oowintool [option] ...\n";
43 print " encoding options\n";
44 print " -w - windows form\n";
45 print " -u - unix form (default)\n";
46 print " commands:\n";
Tor Lillqvistfd4c8792011-10-04 23:56:02 +030047 print " --msvc-ver - print version of MSVC eg. 6.0\n";
Rüdiger Timme35fbf72006-05-05 07:11:16 +000048 print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
Jan Holesovsky41e995e2011-11-16 20:59:16 +010049 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";
Tor Lillqvistfd4c8792011-10-04 23:56:02 +030051 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";
Tor Lillqvistfd4c8792011-10-04 23:56:02 +030057 print " --help - print this message\n";
Rüdiger Timme35fbf72006-05-05 07:11:16 +000058}
59
60sub cygpath($$$)
61{
62 my ($path, $input_format, $format) = @_;
63
Jens-Heiner Rechtien84155952007-06-27 16:51:45 +000064 return $path if ( ! defined $path );
Rüdiger Timme35fbf72006-05-05 07:11:16 +000065 # Strip trailing path separators
66 if ($input_format eq 'u') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +020067 $path =~ s|/*\s*$||;
Rüdiger Timme35fbf72006-05-05 07:11:16 +000068 } else {
Tor Lillqvistdcc90962012-03-09 10:35:20 +020069 $path =~ s|\\*\s*$||;
Rüdiger Timme35fbf72006-05-05 07:11:16 +000070 }
71
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') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +020075 $path =~ s|\\|/|g;
76 $path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
Rüdiger Timme35fbf72006-05-05 07:11:16 +000077 }
78 elsif ($format eq 'w' && $input_format eq 'u') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +020079 $path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
80 $path =~ s|/|\\|g;
Rüdiger Timme35fbf72006-05-05 07:11:16 +000081 }
82
83 return $path;
84}
85
86sub print_path($$)
87{
88 my ($path, $unix) = @_;
89
90 $path = cygpath ($path, $unix, $output_format);
Tor Lillqvistdcc90962012-03-09 10:35:20 +020091
Rüdiger Timme35fbf72006-05-05 07:11:16 +000092 print $path;
93}
94
Tor Lillqvist699d1192011-05-16 15:52:26 +030095sub print_windows_sdk_home()
Rüdiger Timme35fbf72006-05-05 07:11:16 +000096{
Rüdiger Timm557681e2008-09-05 13:14:13 +000097 my ($value, $key);
Rüdiger Timm557681e2008-09-05 13:14:13 +000098
Tor Lillqvistdcc90962012-03-09 10:35:20 +020099 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
100
101 if (!defined $value) {
102 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.1/InstallationFolder');
103 }
104
105 if (!defined $value) {
106 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
107 }
108
109 if (!defined $value) {
110 $value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
111 }
112
113 if (!defined $value) {
114 $key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
115 $value = reg_get_value ($key);
116 }
117
118 defined $value || die "Windows SDK not found";
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000119
120 print cygpath ($value, 'w', $output_format);
121}
122
Rüdiger Timm9eb4ff02008-07-31 17:36:04 +0000123my %msvs_2008 = (
124 'ver' => '9.0',
125 'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
Rüdiger Timm9eb4ff02008-07-31 17:36:04 +0000126 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
127 'dll_suffix' => '90'
128);
129my %msvc_2008 = (
130 'ver' => '9.0',
131 'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
Rüdiger Timm9eb4ff02008-07-31 17:36:04 +0000132 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
133 'dll_suffix' => '90'
134);
Rüdiger Timm557681e2008-09-05 13:14:13 +0000135my %msvs_express_2008 = (
136 'ver' => '9.0',
137 'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
Rüdiger Timm557681e2008-09-05 13:14:13 +0000138 'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
139 'dll_suffix' => '90'
140);
141my %msvc_express_2008 = (
142 'ver' => '9.0',
143 'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
Rüdiger Timm557681e2008-09-05 13:14:13 +0000144 'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
145 'dll_suffix' => '90'
146);
Jesús Corriusf0687902010-10-15 01:36:09 +0200147my %msvs_2010 = (
148 'ver' => '10.0',
149 'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
Jesús Corriusf0687902010-10-15 01:36:09 +0200150 'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
151 'dll_suffix' => '100'
152);
Jesús Corriusf0687902010-10-15 01:36:09 +0200153my %msvc_2010 = (
154 'ver' => '10.0',
155 'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
Jesús Corriusf0687902010-10-15 01:36:09 +0200156 'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
157 'dll_suffix' => '100'
158);
159
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000160sub find_msvs()
161{
Tor Lillqvist0533d542011-03-15 11:29:52 +0200162 my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000163
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200164 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;
168 return $ver;
169 }
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000170 }
171 die "Can't find MS Visual Studio / VC++";
172}
173
174sub find_msvc()
175{
Tor Lillqvist0533d542011-03-15 11:29:52 +0200176 my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000177
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200178 for $ver (@ms_versions) {
179 my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
180 if (defined $install && $install ne '') {
181 $ver->{'product_dir'} = $install;
182 return $ver;
183 }
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000184 }
185 die "Can't find MS Visual Studio / VC++";
186}
187
188sub print_msvc_ver()
189{
190 my $ver = find_msvc();
191 print $ver->{'ver'};
192}
193
194sub print_msvc_product_dir()
195{
196 my $ver = find_msvc();
197 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
198}
199
200sub print_msvs_productdir()
201{
202 my $ver = find_msvs();
203 print cygpath ($ver->{'product_dir'}, 'w', $output_format);
204}
205
206sub print_csc_compiler_dir()
207{
Rüdiger Timm557681e2008-09-05 13:14:13 +0000208 my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
Tor Lillqvist5e9e4c52011-03-15 11:29:49 +0200209 my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
210 `/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
211 `/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
Rüdiger Timm557681e2008-09-05 13:14:13 +0000212 print `dirname $csc_exe`;
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000213}
214
215sub print_dotnetsdk_dir()
216{
Rüdiger Timm557681e2008-09-05 13:14:13 +0000217 my $dir =
218 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
219 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
Jesús Corriusc87a8752010-10-15 23:47:37 +0200220 if ($dir) {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200221 print cygpath ($dir, 'w', $output_format);
Jesús Corriusc87a8752010-10-15 23:47:37 +0200222 }
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000223}
224
225sub print_jdk_dir()
226{
Kurt Zenker7eb67202007-12-12 12:24:57 +0000227 my $dir =
Caolán McNamara32781c2d2012-03-01 16:37:08 +0000228 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.7/JavaHome") ||
229 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200230 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.4/JavaHome") ||
232 reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000233 print cygpath($dir, 'w', $output_format);
234}
235
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000236sub copy_dll($$$)
237{
238 my ($src, $fname, $dest) = @_;
239
240 -f "$src/$fname" || die "can't find $src";
241 -d $dest || die "no directory $dest";
242
Caolán McNamaraa9102042011-11-23 10:09:22 +0000243 print STDERR "Copying $src/$fname to $dest\n";
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000244 copy ("$src/$fname", $dest) || die "copy failed: $!";
245 chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
246}
247
248sub msvc_find_version($)
249{
250 my $checkpath = shift;
251 my $ver = find_msvc();
252 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200253 $ver->{$checkpath});
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000254 -d $srcdir && return $ver;
255 $ver = find_msvs();
256 $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200257 $ver->{$checkpath});
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000258 -d $srcdir && return $ver;
Rüdiger Timm9eb4ff02008-07-31 17:36:04 +0000259 return undef;
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000260}
261
262sub msvc_copy_dlls($)
263{
264 my $dest = shift;
265 my $ver = msvc_find_version('dll_path');
266 defined $ver || return;
267 my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200268 $ver->{'dll_path'});
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000269
270 copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200271 $dest . $ver->{'dll_suffix'});
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000272 copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200273 $dest . $ver->{'dll_suffix'});
Jesús Corriusf0687902010-10-15 01:36:09 +0200274 if ($ver->{'dll_suffix'} == 90) {
Rüdiger Timm9eb4ff02008-07-31 17:36:04 +0000275 copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
276 $dest . $ver->{'dll_suffix'});
277 copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
278 }
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000279}
280
Jan Holesovsky41e995e2011-11-16 20:59:16 +0100281sub msvc_copy_msms($$)
Andras Timarb667ca52011-10-21 10:13:48 +0200282{
Jan Holesovsky41e995e2011-11-16 20:59:16 +0100283 # $postfix is empty for x86, and '_x64' for x64
284 my ($dest, $postfix) = @_;
Andras Timarb667ca52011-10-21 10:13:48 +0200285 my $common_files_path = $ENV{"CommonProgramFiles(x86)"};
286 if (!defined $common_files_path) {
287 $common_files_path = $ENV{CommonProgramFiles};
Caolán McNamaraa9102042011-11-23 10:09:22 +0000288 if (!defined $common_files_path) {
289 $common_files_path = "C:\\Program Files\\Common Files";
290 }
Andras Timarb667ca52011-10-21 10:13:48 +0200291 }
Caolán McNamaraa9102042011-11-23 10:09:22 +0000292
293 defined $common_files_path || die "Windows CommonProgramFiles not found";
294
Andras Timarb667ca52011-10-21 10:13:48 +0200295 my $msm_path = (cygpath $common_files_path . "\\Merge Modules", 'w', $output_format);
Jan Holesovsky41e995e2011-11-16 20:59:16 +0100296 foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
Caolán McNamaraa9102042011-11-23 10:09:22 +0000297 print STDERR "Copying $msm_path/$fname to $dest\n";
Andras Timarb667ca52011-10-21 10:13:48 +0200298 copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
299 }
300}
301
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000302if (!@ARGV) {
303 print_syntax();
304 exit 1;
305}
306
307my @commands = ();
308my $opt;
309while (@ARGV) {
310 $opt = shift @ARGV;
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200311
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000312 if ($opt eq '-w' || $opt eq '-u') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200313 $output_format = substr($opt, 1, 1);
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000314 } else {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200315 push @commands, $opt;
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000316 }
317}
318
319while (@commands) {
320 $opt = shift @commands;
321
322 if (0) {
323 } elsif ($opt eq '--msvc-ver') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200324 print_msvc_ver();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000325 } elsif ($opt eq '--msvc-copy-dlls') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200326 my $dest = shift @commands;
327 defined $dest || die "copy-dlls requires a destination directory";
328 msvc_copy_dlls( $dest );
Andras Timarb667ca52011-10-21 10:13:48 +0200329 } elsif ($opt eq '--msvc-copy-msms') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200330 my $dest = shift @commands;
331 defined $dest || die "copy-msms requires a destination directory";
332 msvc_copy_msms( $dest, '' );
Jan Holesovsky41e995e2011-11-16 20:59:16 +0100333 } elsif ($opt eq '--msvc-copy-msms-64') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200334 my $dest = shift @commands;
335 defined $dest || die "copy-msms-64 requires a destination directory";
336 msvc_copy_msms( $dest, '_x64' );
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000337 } elsif ($opt eq '--msvs-productdir') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200338 print_msvs_productdir();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000339 } elsif ($opt eq '--msvc-productdir') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200340 print_msvc_product_dir();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000341 } elsif ($opt eq '--dotnetsdk-dir') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200342 print_dotnetsdk_dir();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000343 } elsif ($opt eq '--csc-compilerdir') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200344 print_csc_compiler_dir();
Tor Lillqvist699d1192011-05-16 15:52:26 +0300345 } elsif ($opt eq '--windows-sdk-home') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200346 print_windows_sdk_home();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000347 } elsif ($opt eq '--jdk-home') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200348 print_jdk_dir();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000349 } elsif ($opt eq '--help' || $opt eq '/?') {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200350 print_syntax();
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000351 } else {
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200352 print "Unknown option '$opt'\n";
353 print_syntax();
354 exit 1;
Rüdiger Timme35fbf72006-05-05 07:11:16 +0000355 }
356}
357
Tor Lillqvistdcc90962012-03-09 10:35:20 +0200358# vim:set shiftwidth=4 softtabstop=4 expandtab: