2006-05-05 02:11:16 -05:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use File::Copy;
|
|
|
|
|
|
|
|
my $output_format = 'u';
|
|
|
|
|
|
|
|
sub reg_get_value($)
|
|
|
|
{
|
|
|
|
# it is believed that the registry moves keys around
|
|
|
|
# depending on OS version, this will de-mangle that
|
|
|
|
my $key = shift;
|
|
|
|
my $fhandle;
|
|
|
|
my $value;
|
|
|
|
|
|
|
|
open ($fhandle, "/proc/registry/$key") || return;
|
|
|
|
# reg keys have 0x00 0x5c at the end
|
|
|
|
$value = (split /\0/, <$fhandle>)[0];
|
|
|
|
close ($fhandle);
|
|
|
|
|
2007-06-27 11:51:45 -05:00
|
|
|
if ( defined $value ) {
|
|
|
|
chomp ($value);
|
|
|
|
$value =~ s|\r\n||;
|
2006-05-05 02:11:16 -05:00
|
|
|
# print "Value '$value' at '$key'\n";
|
2007-06-27 11:51:45 -05:00
|
|
|
}
|
2006-05-05 02:11:16 -05:00
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub reg_find_key($)
|
|
|
|
{
|
|
|
|
# it is believed that the registry moves keys around
|
|
|
|
# depending on OS version, this will de-mangle that
|
|
|
|
my $key = shift;
|
|
|
|
$key =~ s| |\\ |;
|
|
|
|
$key = `cd /proc/registry/ ; ls $key`;
|
|
|
|
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_syntax()
|
|
|
|
{
|
|
|
|
print "oowintool [option] ...\n";
|
|
|
|
print " encoding options\n";
|
|
|
|
print " -w - windows form\n";
|
|
|
|
print " -u - unix form (default)\n";
|
|
|
|
print " commands:\n";
|
2011-10-04 15:56:02 -05:00
|
|
|
print " --msvc-ver - print version of MSVC eg. 6.0\n";
|
2006-05-05 02:11:16 -05:00
|
|
|
print " --msvc-copy-dlls <dest> - copy msvc[pr]??.dlls into <dest>/msvcp??/\n";
|
2011-11-16 13:59:16 -06:00
|
|
|
print " --msvc-copy-msms <dest> - copy mscrt merge modules to <dest>/msm90/\n";
|
|
|
|
print " --msvc-copy-msms-64 <ds>- copy the x64 mscrt merge modules to <ds>/msm90/\n";
|
2011-10-04 15:56:02 -05:00
|
|
|
print " --msvc-productdir - print productdir\n";
|
|
|
|
print " --msvs-productdir - print productdir\n";
|
|
|
|
print " --dotnetsdk-dir - print .NET SDK path\n";
|
|
|
|
print " --csc-compilerdir - print .NET SDK compiler path\n";
|
|
|
|
print " --windows-sdk-home - print Windows SDK install dir\n";
|
|
|
|
print " --jdk-home - print the jdk install dir\n";
|
|
|
|
print " --nsis-dir - print NSIS path\n";
|
|
|
|
print " --help - print this message\n";
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub cygpath($$$)
|
|
|
|
{
|
|
|
|
my ($path, $input_format, $format) = @_;
|
|
|
|
|
2007-06-27 11:51:45 -05:00
|
|
|
return $path if ( ! defined $path );
|
2006-05-05 02:11:16 -05:00
|
|
|
# Strip trailing path separators
|
|
|
|
if ($input_format eq 'u') {
|
|
|
|
$path =~ s|/*\s*$||;
|
|
|
|
} else {
|
|
|
|
$path =~ s|\\*\s*$||;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 'Unterminated quoted string errors' from 'ash' when
|
|
|
|
# forking cygpath so - reimplement cygpath in perl [ gack ]
|
|
|
|
if ($format eq 'u' && $input_format eq 'w') {
|
|
|
|
$path =~ s|\\|/|g;
|
|
|
|
$path =~ s|([a-zA-Z]):/|/cygdrive/$1/|g;
|
|
|
|
}
|
|
|
|
elsif ($format eq 'w' && $input_format eq 'u') {
|
|
|
|
$path =~ s|/cygdrive/([a-zA-Z])/|/$1/|g;
|
|
|
|
$path =~ s|/|\\|g;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_path($$)
|
|
|
|
{
|
|
|
|
my ($path, $unix) = @_;
|
|
|
|
|
|
|
|
$path = cygpath ($path, $unix, $output_format);
|
|
|
|
|
|
|
|
print $path;
|
|
|
|
}
|
|
|
|
|
2011-05-16 07:52:26 -05:00
|
|
|
sub print_windows_sdk_home()
|
2006-05-05 02:11:16 -05:00
|
|
|
{
|
2008-09-05 08:14:13 -05:00
|
|
|
my ($value, $key);
|
2008-07-31 12:36:04 -05:00
|
|
|
$value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v6.1/InstallationFolder');
|
2006-05-05 02:11:16 -05:00
|
|
|
if (!defined $value)
|
|
|
|
{
|
2008-09-05 08:14:13 -05:00
|
|
|
$value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder');
|
|
|
|
}
|
|
|
|
if (!defined $value)
|
|
|
|
{
|
|
|
|
$value = reg_get_value ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/Directories/Install Dir');
|
2008-07-31 12:36:04 -05:00
|
|
|
}
|
2008-09-05 08:14:13 -05:00
|
|
|
if (!defined $value)
|
|
|
|
{
|
|
|
|
$key = reg_find_key ('HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/*/Install Dir');
|
|
|
|
$value = reg_get_value ($key);
|
|
|
|
}
|
|
|
|
if (!defined $value)
|
|
|
|
{
|
|
|
|
my $dir = cygpath (find_msvc()->{'product_dir'}, 'w', $output_format);
|
|
|
|
$value = `/bin/find "$dir" -iname platformsdk | head -n 1`;
|
|
|
|
}
|
|
|
|
|
2011-05-16 07:52:26 -05:00
|
|
|
defined $value || die "Windows Sdk not found";
|
2006-05-05 02:11:16 -05:00
|
|
|
|
|
|
|
print cygpath ($value, 'w', $output_format);
|
|
|
|
}
|
|
|
|
|
2008-07-31 12:36:04 -05:00
|
|
|
my %msvs_2008 = (
|
|
|
|
'ver' => '9.0',
|
|
|
|
'key' => 'Microsoft/VisualStudio/9.0/Setup/VS/ProductDir',
|
|
|
|
'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
|
|
|
|
'dll_suffix' => '90'
|
|
|
|
);
|
|
|
|
my %msvc_2008 = (
|
|
|
|
'ver' => '9.0',
|
|
|
|
'key' => 'Microsoft/VisualStudio/9.0/Setup/VC/ProductDir',
|
|
|
|
'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
|
|
|
|
'dll_suffix' => '90'
|
|
|
|
);
|
2008-09-05 08:14:13 -05:00
|
|
|
my %msvs_express_2008 = (
|
|
|
|
'ver' => '9.0',
|
|
|
|
'key' => 'Microsoft/VCExpress/9.0/Setup/VS/ProductDir',
|
|
|
|
'dll_path' => 'VC/redist/x86/Microsoft.VC90.CRT',
|
|
|
|
'dll_suffix' => '90'
|
|
|
|
);
|
|
|
|
my %msvc_express_2008 = (
|
|
|
|
'ver' => '9.0',
|
|
|
|
'key' => 'Microsoft/VCExpress/9.0/Setup/VC/ProductDir',
|
|
|
|
'dll_path' => 'redist/x86/Microsoft.VC90.CRT',
|
|
|
|
'dll_suffix' => '90'
|
|
|
|
);
|
2010-10-14 18:36:09 -05:00
|
|
|
my %msvs_2010 = (
|
|
|
|
'ver' => '10.0',
|
|
|
|
'key' => 'Microsoft/VisualStudio/10.0/Setup/VS/ProductDir',
|
|
|
|
'dll_path' => 'VC/redist/x86/Microsoft.VC100.CRT',
|
|
|
|
'dll_suffix' => '100'
|
|
|
|
);
|
|
|
|
my %msvc_2010 = (
|
|
|
|
'ver' => '10.0',
|
|
|
|
'key' => 'Microsoft/VisualStudio/10.0/Setup/VC/ProductDir',
|
|
|
|
'dll_path' => 'redist/x86/Microsoft.VC100.CRT',
|
|
|
|
'dll_suffix' => '100'
|
|
|
|
);
|
|
|
|
|
2006-05-05 02:11:16 -05:00
|
|
|
sub find_msvs()
|
|
|
|
{
|
2011-03-15 04:29:52 -05:00
|
|
|
my @ms_versions = ( \%msvs_2008, \%msvs_express_2008, \%msvs_2010 );
|
2006-05-05 02:11:16 -05:00
|
|
|
|
|
|
|
for $ver (@ms_versions)
|
|
|
|
{
|
|
|
|
my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
|
|
|
|
if (defined $install && $install ne '') {
|
|
|
|
$ver->{'product_dir'} = $install;
|
|
|
|
return $ver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die "Can't find MS Visual Studio / VC++";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub find_msvc()
|
|
|
|
{
|
2011-03-15 04:29:52 -05:00
|
|
|
my @ms_versions = ( \%msvc_2008, \%msvc_express_2008, \%msvc_2010 );
|
2006-05-05 02:11:16 -05:00
|
|
|
|
|
|
|
for $ver (@ms_versions)
|
|
|
|
{
|
|
|
|
my $install = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/" . $ver->{'key'});
|
|
|
|
if (defined $install && $install ne '') {
|
|
|
|
$ver->{'product_dir'} = $install;
|
|
|
|
return $ver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die "Can't find MS Visual Studio / VC++";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_msvc_ver()
|
|
|
|
{
|
|
|
|
my $ver = find_msvc();
|
|
|
|
print $ver->{'ver'};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_msvc_product_dir()
|
|
|
|
{
|
|
|
|
my $ver = find_msvc();
|
|
|
|
print cygpath ($ver->{'product_dir'}, 'w', $output_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_msvs_productdir()
|
|
|
|
{
|
|
|
|
my $ver = find_msvs();
|
|
|
|
print cygpath ($ver->{'product_dir'}, 'w', $output_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_csc_compiler_dir()
|
|
|
|
{
|
2008-09-05 08:14:13 -05:00
|
|
|
my $dir = cygpath (reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/InstallRoot"), 'w', $output_format);
|
2011-03-15 04:29:49 -05:00
|
|
|
my $csc_exe = `/bin/find "$dir" -iname csc.exe | grep "v3\.5\." | head -n 1` ||
|
|
|
|
`/bin/find "$dir" -iname csc.exe | grep "v4\." | head -n 1` ||
|
|
|
|
`/bin/find "$dir" -iname csc.exe | grep "v2\." | head -n 1`;
|
2008-09-05 08:14:13 -05:00
|
|
|
print `dirname $csc_exe`;
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_dotnetsdk_dir()
|
|
|
|
{
|
2008-09-05 08:14:13 -05:00
|
|
|
my $dir =
|
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv1.1") ||
|
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/.NETFramework/sdkInstallRootv2.0");
|
2010-10-15 16:47:37 -05:00
|
|
|
if ($dir) {
|
|
|
|
print cygpath ($dir, 'w', $output_format);
|
|
|
|
}
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_jdk_dir()
|
|
|
|
{
|
2007-12-12 06:24:57 -06:00
|
|
|
my $dir =
|
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.5/JavaHome") ||
|
2010-09-14 03:54:49 -05:00
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.6/JavaHome") ||
|
2008-09-05 08:14:13 -05:00
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.4/JavaHome") ||
|
|
|
|
reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java\ Development\ Kit/1.3/JavaHome");
|
2006-05-05 02:11:16 -05:00
|
|
|
print cygpath($dir, 'w', $output_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub print_nsis_dir()
|
|
|
|
{
|
|
|
|
my $dir = reg_get_value ("HKEY_LOCAL_MACHINE/SOFTWARE/NSIS/@");
|
2007-06-27 11:51:45 -05:00
|
|
|
print cygpath ($dir, 'w', $output_format) if defined $dir;
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub copy_dll($$$)
|
|
|
|
{
|
|
|
|
my ($src, $fname, $dest) = @_;
|
|
|
|
|
|
|
|
-f "$src/$fname" || die "can't find $src";
|
|
|
|
-d $dest || die "no directory $dest";
|
|
|
|
|
2011-11-23 04:09:22 -06:00
|
|
|
print STDERR "Copying $src/$fname to $dest\n";
|
2006-05-05 02:11:16 -05:00
|
|
|
copy ("$src/$fname", $dest) || die "copy failed: $!";
|
|
|
|
chmod (0755, "$dest/$fname") || die "failed to set dll executable: $!";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub msvc_find_version($)
|
|
|
|
{
|
|
|
|
my $checkpath = shift;
|
|
|
|
my $ver = find_msvc();
|
|
|
|
my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
|
|
|
|
$ver->{$checkpath});
|
|
|
|
-d $srcdir && return $ver;
|
|
|
|
$ver = find_msvs();
|
|
|
|
$srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
|
|
|
|
$ver->{$checkpath});
|
|
|
|
-d $srcdir && return $ver;
|
2008-07-31 12:36:04 -05:00
|
|
|
return undef;
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub msvc_copy_dlls($)
|
|
|
|
{
|
|
|
|
my $dest = shift;
|
|
|
|
my $ver = msvc_find_version('dll_path');
|
|
|
|
defined $ver || return;
|
|
|
|
my $srcdir = (cygpath ($ver->{'product_dir'}, 'w', 'u') . '/' .
|
|
|
|
$ver->{'dll_path'});
|
|
|
|
|
|
|
|
copy_dll ($srcdir, "msvcp" . $ver->{'dll_suffix'} . ".dll",
|
|
|
|
$dest . $ver->{'dll_suffix'});
|
|
|
|
copy_dll ($srcdir, "msvcr" . $ver->{'dll_suffix'} . ".dll",
|
|
|
|
$dest . $ver->{'dll_suffix'});
|
2010-10-14 18:36:09 -05:00
|
|
|
if ($ver->{'dll_suffix'} == 90) {
|
2008-07-31 12:36:04 -05:00
|
|
|
copy_dll ($srcdir, "msvcm" . $ver->{'dll_suffix'} . ".dll",
|
|
|
|
$dest . $ver->{'dll_suffix'});
|
|
|
|
copy_dll ($srcdir, "Microsoft.VC90.CRT.manifest", $dest . $ver->{'dll_suffix'});
|
|
|
|
}
|
2006-05-05 02:11:16 -05:00
|
|
|
}
|
|
|
|
|
2011-11-16 13:59:16 -06:00
|
|
|
sub msvc_copy_msms($$)
|
2011-10-21 03:13:48 -05:00
|
|
|
{
|
2011-11-16 13:59:16 -06:00
|
|
|
# $postfix is empty for x86, and '_x64' for x64
|
|
|
|
my ($dest, $postfix) = @_;
|
2011-10-21 03:13:48 -05:00
|
|
|
my $common_files_path = $ENV{"CommonProgramFiles(x86)"};
|
|
|
|
if (!defined $common_files_path) {
|
|
|
|
$common_files_path = $ENV{CommonProgramFiles};
|
2011-11-23 04:09:22 -06:00
|
|
|
if (!defined $common_files_path) {
|
|
|
|
$common_files_path = "C:\\Program Files\\Common Files";
|
|
|
|
}
|
2011-10-21 03:13:48 -05:00
|
|
|
}
|
2011-11-23 04:09:22 -06:00
|
|
|
|
|
|
|
defined $common_files_path || die "Windows CommonProgramFiles not found";
|
|
|
|
|
2011-10-21 03:13:48 -05:00
|
|
|
my $msm_path = (cygpath $common_files_path . "\\Merge Modules", 'w', $output_format);
|
2011-11-16 13:59:16 -06:00
|
|
|
foreach $fname ("Microsoft_VC90_CRT_x86$postfix.msm", "policy_9_0_Microsoft_VC90_CRT_x86$postfix.msm") {
|
2011-11-23 04:09:22 -06:00
|
|
|
print STDERR "Copying $msm_path/$fname to $dest\n";
|
2011-10-21 03:13:48 -05:00
|
|
|
copy ("$msm_path/$fname", $dest) || die "copy failed: $!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-05 02:11:16 -05:00
|
|
|
if (!@ARGV) {
|
|
|
|
print_syntax();
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @commands = ();
|
|
|
|
my $opt;
|
|
|
|
while (@ARGV) {
|
|
|
|
$opt = shift @ARGV;
|
|
|
|
|
|
|
|
if ($opt eq '-w' || $opt eq '-u') {
|
|
|
|
$output_format = substr($opt, 1, 1);
|
|
|
|
} else {
|
|
|
|
push @commands, $opt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (@commands) {
|
|
|
|
$opt = shift @commands;
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
} elsif ($opt eq '--msvc-ver') {
|
|
|
|
print_msvc_ver();
|
|
|
|
} elsif ($opt eq '--msvc-copy-dlls') {
|
|
|
|
my $dest = shift @commands;
|
|
|
|
defined $dest || die "copy-dlls requires a destination directory";
|
|
|
|
msvc_copy_dlls( $dest );
|
2011-10-21 03:13:48 -05:00
|
|
|
} elsif ($opt eq '--msvc-copy-msms') {
|
|
|
|
my $dest = shift @commands;
|
|
|
|
defined $dest || die "copy-msms requires a destination directory";
|
2011-11-16 13:59:16 -06:00
|
|
|
msvc_copy_msms( $dest, '' );
|
|
|
|
} elsif ($opt eq '--msvc-copy-msms-64') {
|
|
|
|
my $dest = shift @commands;
|
|
|
|
defined $dest || die "copy-msms-64 requires a destination directory";
|
|
|
|
msvc_copy_msms( $dest, '_x64' );
|
2006-05-05 02:11:16 -05:00
|
|
|
} elsif ($opt eq '--msvs-productdir') {
|
|
|
|
print_msvs_productdir();
|
|
|
|
} elsif ($opt eq '--msvc-productdir') {
|
|
|
|
print_msvc_product_dir();
|
|
|
|
} elsif ($opt eq '--dotnetsdk-dir') {
|
|
|
|
print_dotnetsdk_dir();
|
|
|
|
} elsif ($opt eq '--csc-compilerdir') {
|
|
|
|
print_csc_compiler_dir();
|
2011-05-16 07:52:26 -05:00
|
|
|
} elsif ($opt eq '--windows-sdk-home') {
|
|
|
|
print_windows_sdk_home();
|
2006-05-05 02:11:16 -05:00
|
|
|
} elsif ($opt eq '--jdk-home') {
|
|
|
|
print_jdk_dir();
|
|
|
|
} elsif ($opt eq '--nsis-dir') {
|
|
|
|
print_nsis_dir();
|
|
|
|
} elsif ($opt eq '--help' || $opt eq '/?') {
|
|
|
|
print_syntax();
|
|
|
|
} else {
|
|
|
|
print "Unknown option '$opt'\n";
|
|
|
|
print_syntax();
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|