Commit f9c5d3e5 authored by Magnus Hagander's avatar Magnus Hagander

Detect a 64-bit build environment on Windows, and generate the appropriate

project files.

Based on the work of Tsutomu Yamada, but much refactored.
parent 5069e959
...@@ -3,7 +3,7 @@ package Project; ...@@ -3,7 +3,7 @@ package Project;
# #
# Package that encapsulates a Visual C++ project file generation # Package that encapsulates a Visual C++ project file generation
# #
# $PostgreSQL: pgsql/src/tools/msvc/Project.pm,v 1.22 2009/12/23 13:27:04 mha Exp $ # $PostgreSQL: pgsql/src/tools/msvc/Project.pm,v 1.23 2010/01/01 17:34:25 mha Exp $
# #
use Carp; use Carp;
use strict; use strict;
...@@ -33,7 +33,8 @@ sub new ...@@ -33,7 +33,8 @@ sub new
solution => $solution, solution => $solution,
disablewarnings => '4018;4244;4273;4102;4090', disablewarnings => '4018;4244;4273;4102;4090',
disablelinkerwarnings => '', disablelinkerwarnings => '',
vcver => $solution->{vcver} vcver => $solution->{vcver},
platform => $solution->{platform},
}; };
bless $self; bless $self;
...@@ -391,7 +392,7 @@ EOF ...@@ -391,7 +392,7 @@ EOF
$of =~ s/\.y$/.c/; $of =~ s/\.y$/.c/;
$of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c}; $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
print F '>' print F '>'
. GenerateCustomTool('Running bison on ' . $f, . $self->GenerateCustomTool('Running bison on ' . $f,
'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of) 'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of)
. '</File>' . "\n"; . '</File>' . "\n";
} }
...@@ -400,7 +401,7 @@ EOF ...@@ -400,7 +401,7 @@ EOF
my $of = $f; my $of = $f;
$of =~ s/\.l$/.c/; $of =~ s/\.l$/.c/;
print F '>' print F '>'
. GenerateCustomTool('Running flex on ' . $f, 'src\tools\msvc\pgflex.bat ' . $f,$of) . $self->GenerateCustomTool('Running flex on ' . $f, 'src\tools\msvc\pgflex.bat ' . $f,$of)
. '</File>' . "\n"; . '</File>' . "\n";
} }
elsif (defined($uniquefiles{$file})) elsif (defined($uniquefiles{$file}))
...@@ -410,8 +411,8 @@ EOF ...@@ -410,8 +411,8 @@ EOF
my $obj = $dir; my $obj = $dir;
$obj =~ s/\\/_/g; $obj =~ s/\\/_/g;
print F print F
"><FileConfiguration Name=\"Debug|Win32\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj" "><FileConfiguration Name=\"Debug|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
. "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|Win32\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj" . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
. "_$file.obj\" /></FileConfiguration></File>\n"; . "_$file.obj\" /></FileConfiguration></File>\n";
} }
else else
...@@ -431,14 +432,14 @@ EOF ...@@ -431,14 +432,14 @@ EOF
sub GenerateCustomTool sub GenerateCustomTool
{ {
my ($desc, $tool, $output, $cfg) = @_; my ($self, $desc, $tool, $output, $cfg) = @_;
if (!defined($cfg)) if (!defined($cfg))
{ {
return GenerateCustomTool($desc, $tool, $output, 'Debug') return $self->GenerateCustomTool($desc, $tool, $output, 'Debug') .
.GenerateCustomTool($desc, $tool, $output, 'Release'); $self->GenerateCustomTool($desc, $tool, $output, 'Release');
} }
return return
"<FileConfiguration Name=\"$cfg|Win32\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>"; "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
} }
sub WriteReferences sub WriteReferences
...@@ -460,7 +461,7 @@ sub WriteHeader ...@@ -460,7 +461,7 @@ sub WriteHeader
print $f <<EOF; print $f <<EOF;
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}"> <VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}">
<Platforms><Platform Name="Win32"/></Platforms> <Platforms><Platform Name="$self->{platform}"/></Platforms>
<Configurations> <Configurations>
EOF EOF
$self->WriteConfiguration($f, 'Debug', $self->WriteConfiguration($f, 'Debug',
...@@ -493,8 +494,9 @@ sub WriteConfiguration ...@@ -493,8 +494,9 @@ sub WriteConfiguration
} }
$libs =~ s/ $//; $libs =~ s/ $//;
$libs =~ s/__CFGNAME__/$cfgname/g; $libs =~ s/__CFGNAME__/$cfgname/g;
my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
print $f <<EOF; print $f <<EOF;
<Configuration Name="$cfgname|Win32" OutputDirectory=".\\$cfgname\\$self->{name}" IntermediateDirectory=".\\$cfgname\\$self->{name}" <Configuration Name="$cfgname|$self->{platform}" OutputDirectory=".\\$cfgname\\$self->{name}" IntermediateDirectory=".\\$cfgname\\$self->{name}"
ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2" WholeProgramOptimization="$p->{wholeopt}"> ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2" WholeProgramOptimization="$p->{wholeopt}">
<Tool Name="VCCLCompilerTool" Optimization="$p->{opt}" <Tool Name="VCCLCompilerTool" Optimization="$p->{opt}"
AdditionalIncludeDirectories="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}" AdditionalIncludeDirectories="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
...@@ -513,7 +515,7 @@ EOF ...@@ -513,7 +515,7 @@ EOF
StackReserveSize="4194304" DisableSpecificWarnings="$self->{disablewarnings}" StackReserveSize="4194304" DisableSpecificWarnings="$self->{disablewarnings}"
GenerateDebugInformation="TRUE" ProgramDatabaseFile=".\\$cfgname\\$self->{name}\\$self->{name}.pdb" GenerateDebugInformation="TRUE" ProgramDatabaseFile=".\\$cfgname\\$self->{name}\\$self->{name}.pdb"
GenerateMapFile="FALSE" MapFileName=".\\$cfgname\\$self->{name}\\$self->{name}.map" GenerateMapFile="FALSE" MapFileName=".\\$cfgname\\$self->{name}\\$self->{name}.map"
SubSystem="1" TargetMachine="1" SubSystem="1" TargetMachine="$targetmachine"
EOF EOF
if ($self->{disablelinkerwarnings}) if ($self->{disablelinkerwarnings})
{ {
...@@ -540,7 +542,7 @@ EOF ...@@ -540,7 +542,7 @@ EOF
if ($self->{builddef}) if ($self->{builddef})
{ {
print $f print $f
"\t<Tool Name=\"VCPreLinkEventTool\" Description=\"Generate DEF file\" CommandLine=\"perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name}\" />\n"; "\t<Tool Name=\"VCPreLinkEventTool\" Description=\"Generate DEF file\" CommandLine=\"perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}\" />\n";
} }
print $f <<EOF; print $f <<EOF;
</Configuration> </Configuration>
......
...@@ -3,7 +3,7 @@ package Solution; ...@@ -3,7 +3,7 @@ package Solution;
# #
# Package that encapsulates a Visual C++ solution file generation # Package that encapsulates a Visual C++ solution file generation
# #
# $PostgreSQL: pgsql/src/tools/msvc/Solution.pm,v 1.50 2009/12/30 12:26:41 mha Exp $ # $PostgreSQL: pgsql/src/tools/msvc/Solution.pm,v 1.51 2010/01/01 17:34:25 mha Exp $
# #
use Carp; use Carp;
use strict; use strict;
...@@ -21,6 +21,7 @@ sub new ...@@ -21,6 +21,7 @@ sub new
numver => '', numver => '',
strver => '', strver => '',
vcver => undef, vcver => undef,
platform => undef,
}; };
bless $self; bless $self;
# integer_datetimes is now the default # integer_datetimes is now the default
...@@ -73,6 +74,19 @@ sub DetermineToolVersions ...@@ -73,6 +74,19 @@ sub DetermineToolVersions
elsif ($1 == 9) { $self->{vcver} = '9.00' } elsif ($1 == 9) { $self->{vcver} = '9.00' }
else { die "Unsupported version of Visual Studio: $1" } else { die "Unsupported version of Visual Studio: $1" }
print "Detected Visual Studio version $self->{vcver}\n"; print "Detected Visual Studio version $self->{vcver}\n";
# Determine if we are in 32 or 64-bit mode. Do this by seeing if CL has
# 64-bit only parameters.
$self->{platform} = 'Win32';
open(P,"cl /? 2>NUL|") || die "cl command not found";
while (<P>) {
if (/^\/favor:</) {
$self->{platform} = 'x64';
last;
}
}
close(P);
print "Detected hardware platform: $self->{platform}\n";
} }
...@@ -109,6 +123,7 @@ sub copyFile ...@@ -109,6 +123,7 @@ sub copyFile
sub GenerateFiles sub GenerateFiles
{ {
my $self = shift; my $self = shift;
my $bits = $self->{platform} eq 'Win32' ? 32 : 64;
# Parse configure.in to get version numbers # Parse configure.in to get version numbers
open(C,"configure.in") || confess("Could not open configure.in for reading\n"); open(C,"configure.in") || confess("Could not open configure.in for reading\n");
...@@ -144,8 +159,7 @@ sub GenerateFiles ...@@ -144,8 +159,7 @@ sub GenerateFiles
{ {
s{PG_VERSION "[^"]+"}{PG_VERSION "$self->{strver}"}; s{PG_VERSION "[^"]+"}{PG_VERSION "$self->{strver}"};
s{PG_VERSION_NUM \d+}{PG_VERSION_NUM $self->{numver}}; s{PG_VERSION_NUM \d+}{PG_VERSION_NUM $self->{numver}};
# XXX: When we support 64-bit, need to remove this hardcoding s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY(z)\n#define PG_VERSION_STR "PostgreSQL $self->{strver}, compiled by Visual C++ build " __STRINGIFY2(_MSC_VER) ", $bits-bit"};
s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY(z)\n#define PG_VERSION_STR "PostgreSQL $self->{strver}, compiled by Visual C++ build " __STRINGIFY2(_MSC_VER) ", 32-bit"};
print O; print O;
} }
print O "#define PG_MAJORVERSION \"$self->{majorver}\"\n"; print O "#define PG_MAJORVERSION \"$self->{majorver}\"\n";
...@@ -446,8 +460,8 @@ EOF ...@@ -446,8 +460,8 @@ EOF
print SLN <<EOF; print SLN <<EOF;
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|$self->{platform}= Debug|$self->{platform}
Release|Win32 = Release|Win32 Release|$self->{platform} = Release|$self->{platform}
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
EOF EOF
...@@ -457,10 +471,10 @@ EOF ...@@ -457,10 +471,10 @@ EOF
foreach my $proj (@{$self->{projects}->{$fld}}) foreach my $proj (@{$self->{projects}->{$fld}})
{ {
print SLN <<EOF; print SLN <<EOF;
$proj->{guid}.Debug|Win32.ActiveCfg = Debug|Win32 $proj->{guid}.Debug|$self->{platform}.ActiveCfg = Debug|$self->{platform}
$proj->{guid}.Debug|Win32.Build.0 = Debug|Win32 $proj->{guid}.Debug|$self->{platform}.Build.0 = Debug|$self->{platform}
$proj->{guid}.Release|Win32.ActiveCfg = Release|Win32 $proj->{guid}.Release|$self->{platform}.ActiveCfg = Release|$self->{platform}
$proj->{guid}.Release|Win32.Build.0 = Release|Win32 $proj->{guid}.Release|$self->{platform}.Build.0 = Release|$self->{platform}
EOF EOF
} }
} }
......
...@@ -2,11 +2,13 @@ my @def; ...@@ -2,11 +2,13 @@ my @def;
# #
# Script that generates a .DEF file for all objects in a directory # Script that generates a .DEF file for all objects in a directory
# #
# $PostgreSQL: pgsql/src/tools/msvc/gendef.pl,v 1.8 2008/01/31 16:30:24 adunstan Exp $ # $PostgreSQL: pgsql/src/tools/msvc/gendef.pl,v 1.9 2010/01/01 17:34:25 mha Exp $
# #
die "Usage: gendef.pl <modulepath>\n" unless ($ARGV[0] =~ /\\([^\\]+$)/); die "Usage: gendef.pl <modulepath> <platform>\n" unless
(($ARGV[0] =~ /\\([^\\]+$)/) && ($ARGV[1] == 'Win32' || $ARGV[1] == 'x64'));
my $defname = uc $1; my $defname = uc $1;
my $platform = $ARGV[1];
if (-f "$ARGV[0]/$defname.def") if (-f "$ARGV[0]/$defname.def")
{ {
...@@ -14,7 +16,7 @@ if (-f "$ARGV[0]/$defname.def") ...@@ -14,7 +16,7 @@ if (-f "$ARGV[0]/$defname.def")
exit(0); exit(0);
} }
print "Generating $defname.DEF from directory $ARGV[0]\n"; print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
while (<$ARGV[0]/*.obj>) while (<$ARGV[0]/*.obj>)
{ {
...@@ -55,7 +57,7 @@ foreach my $f (sort @def) ...@@ -55,7 +57,7 @@ foreach my $f (sort @def)
{ {
next if ($f eq $last); next if ($f eq $last);
$last = $f; $last = $f;
$f =~ s/^_//; $f =~ s/^_// unless ($platform eq "x64"); # win64 has new format of exports
$i++; $i++;
# print DEF " $f \@ $i\n"; # ordinaled exports? # print DEF " $f \@ $i\n"; # ordinaled exports?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment