Update to msvc build sys
Here's a patch that updates the msvc build system. It contains the
changes in Hiroshi-sans patch from about a week ago, so please apply
this patch instead to avoid conflicts. Changes summary:
* Change all references to vcbuild directory, since system was moved to
src\tools\msvc on commit.
* Supports building both Debug and Release binaries now (previously only
debug. debug still default). Difference is mainly in that release
binaries are optimized. Unfortunatly, full program optimization had to
be turned off - more on that later.
* Generate ecpg_config.h which is now generated by configure, and thus
needs to be generated for vc as well.
* Add LDAP library to libpq if used (required for
connection-info-in-ldap)
* Change build.bat to use unix line endings. To committer: please make
sure that the file ends up with all lines with unix line endings, in
case the patch gets mangled in some way.
//Magnus
Attachments:
vcbuild.diffapplication/octet-stream; name=vcbuild.diffDownload
Index: src/tools/msvc/Project.pm
===================================================================
RCS file: c:/prog/cvsrepo/pgsql/pgsql/src/tools/msvc/Project.pm,v
retrieving revision 1.1
diff -c -r1.1 Project.pm
*** src/tools/msvc/Project.pm 4 Sep 2006 21:30:39 -0000 1.1
--- src/tools/msvc/Project.pm 14 Sep 2006 13:12:34 -0000
***************
*** 81,87 ****
while (my $ref = shift) {
push @{$self->{references}},$ref;
! $self->AddLibrary("debug\\" . $ref->{name} . "\\" . $ref->{name} . ".lib") if ($ref->{type} eq "exe");
}
}
--- 81,87 ----
while (my $ref = shift) {
push @{$self->{references}},$ref;
! $self->AddLibrary("__CFGNAME__\\" . $ref->{name} . "\\" . $ref->{name} . ".lib");
}
}
***************
*** 113,120 ****
my ($self, $libname) = @_;
$self->{builddef} = 1;
! $self->{def} = ".\\debug\\$self->{name}\\$self->{name}.def";
! $self->{implib} = "debug\\$self->{name}\\$libname";
}
sub UseDef {
--- 113,120 ----
my ($self, $libname) = @_;
$self->{builddef} = 1;
! $self->{def} = ".\\__CFGNAME__\\$self->{name}\\$self->{name}.def";
! $self->{implib} = "__CFGNAME__\\$self->{name}\\$libname";
}
sub UseDef {
***************
*** 286,304 ****
my $of = $f;
$of =~ s/\.y$/.c/;
$of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
! print F '><FileConfiguration Name="Debug|Win32"><Tool Name="VCCustomBuildTool" Description="Running bison on ' . $f . '" CommandLine="vcbuild\pgbison.bat ' . $f . '" AdditionalDependencies="" Outputs="' . $of . '" /></FileConfiguration></File>' . "\n";
}
elsif ($f =~ /\.l$/) {
my $of = $f;
$of =~ s/\.l$/.c/;
$of =~ s{^src\\pl\\plpgsql\\src\\scan.c$}{src\\pl\\plpgsql\\src\\pl_scan.c};
! print F "><FileConfiguration Name=\"Debug|Win32\"><Tool Name=\"VCCustomBuildTool\" Description=\"Running flex on $f\" CommandLine=\"vcbuild\\pgflex.bat $f\" AdditionalDependencies=\"\" Outputs=\"$of\" /></FileConfiguration></File>\n";
}
elsif (defined($uniquefiles{$file})) {
# File already exists, so fake a new name
my $obj = $dir;
$obj =~ s/\\/_/g;
! print F "><FileConfiguration Name=\"Debug|Win32\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj" . "_$file.obj\" /></FileConfiguration></File>\n";
}
else {
$uniquefiles{$file} = 1;
--- 286,304 ----
my $of = $f;
$of =~ s/\.y$/.c/;
$of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
! print F '>' . GenerateCustomTool('Running bison on ' . $f, 'src\tools\msvc\pgbison.bat ' . $f, $of) . '</File>' . "\n";
}
elsif ($f =~ /\.l$/) {
my $of = $f;
$of =~ s/\.l$/.c/;
$of =~ s{^src\\pl\\plpgsql\\src\\scan.c$}{src\\pl\\plpgsql\\src\\pl_scan.c};
! print F '>' . GenerateCustomTool('Running flex on ' . $f, 'src\tools\msvc\pgflex.bat ' . $f,$of) . '</File>' . "\n";
}
elsif (defined($uniquefiles{$file})) {
# File already exists, so fake a new name
my $obj = $dir;
$obj =~ s/\\/_/g;
! print F "><FileConfiguration Name=\"Debug|Win32\"><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></File>\n";
}
else {
$uniquefiles{$file} = 1;
***************
*** 313,318 ****
--- 313,327 ----
close(F);
}
+ sub GenerateCustomTool {
+ my ($desc, $tool, $output, $cfg) = @_;
+ if (!defined($cfg)) {
+ return GenerateCustomTool($desc, $tool, $output, 'Debug') .
+ GenerateCustomTool($desc, $tool, $output, 'Release');
+ }
+ return "<FileConfiguration Name=\"$cfg|Win32\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
+ }
+
sub WriteReferences {
my ($self, $f) = @_;
print $f " <References>\n";
***************
*** 325,372 ****
sub WriteHeader {
my ($self, $f) = @_;
- my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
-
print $f <<EOF;
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject ProjectType="Visual C++" Version="8.00" Name="$self->{name}" ProjectGUID="$self->{guid}">
<Platforms><Platform Name="Win32"/></Platforms>
<Configurations>
! <Configuration Name="Debug|Win32" OutputDirectory=".\\Debug\\$self->{name}" IntermediateDirectory=".\\Debug\\$self->{name}"
! ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2">
! <Tool Name="VCCLCompilerTool" Optimization="0"
AdditionalIncludeDirectories="src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{solution}->{options}->{pthread};$self->{includes}"
! PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;__WINDOWS__;DEBUG=1;__WIN32__;EXEC_BACKEND;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}"
! RuntimeLibrary="3" DisableSpecificWarnings="$self->{disablewarnings}"
EOF
print $f <<EOF;
! AssemblerOutput="0" AssemblerListingLocation=".\\debug\\$self->{name}\\" ObjectFile=".\\debug\\$self->{name}\\"
! ProgramDataBaseFileName=".\\debug\\$self->{name}\\" BrowseInformation="0"
WarningLevel="3" SuppressStartupBanner="TRUE" DebugInformationFormat="3" CompileAs="0"/>
! <Tool Name="VCLinkerTool" OutputFile=".\\debug\\$self->{name}\\$self->{name}.$self->{type}"
! AdditionalDependencies="$self->{libraries}"
LinkIncremental="0" SuppressStartupBanner="TRUE" AdditionalLibraryDirectories="" IgnoreDefaultLibraryNames="libc"
StackReserveSize="4194304" DisableSpecificWarnings="$self->{disablewarnings}"
! GenerateDebugInformation="TRUE" ProgramDatabaseFile=".\\debug\\$self->{name}\\$self->{name}.pdb"
! GenerateMapFile="FALSE" MapFileName=".\\debug\\$self->{name}\\$self->{name}.map"
SubSystem="1" TargetMachine="1"
EOF
if ($self->{implib}) {
! print $f "\t\tImportLibrary=\"$self->{implib}\"\n";
}
if ($self->{def}) {
! print $f "\t\tModuleDefinitionFile=\"$self->{def}\"\n";
}
print $f "\t/>\n";
! print $f "\t<Tool Name=\"VCLibrarianTool\" OutputFile=\".\\Debug\\$self->{name}\\$self->{name}.lib\" IgnoreDefaultLibraryNames=\"libc\" />\n";
print $f "\t<Tool Name=\"VCResourceCompilerTool\" AdditionalIncludeDirectories=\"src\\include\" />\n";
if ($self->{builddef}) {
! print $f "\t<Tool Name=\"VCPreLinkEventTool\" Description=\"Generate DEF file\" CommandLine=\"perl vcbuild\\gendef.pl debug\\$self->{name}\" />\n";
}
print $f <<EOF;
</Configuration>
- </Configurations>
EOF
}
--- 334,398 ----
sub WriteHeader {
my ($self, $f) = @_;
print $f <<EOF;
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject ProjectType="Visual C++" Version="8.00" Name="$self->{name}" ProjectGUID="$self->{guid}">
<Platforms><Platform Name="Win32"/></Platforms>
<Configurations>
! EOF
! $self->WriteConfiguration($f, 'Debug', { defs=>'_DEBUG;DEBUG=1;', wholeopt=>0 , opt=>0, strpool=>'false', runtime=>3 });
! $self->WriteConfiguration($f, 'Release', { defs=>'', wholeopt=>0, opt=>3, strpool=>'true', runtime=>2 });
! print $f <<EOF;
! </Configurations>
! EOF
! }
!
! sub WriteConfiguration
! {
! my ($self, $f, $cfgname, $p) = @_;
! my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
! my $libs = $self->{libraries};
! $libs =~ s/__CFGNAME__/$cfgname/g;
! print $f <<EOF;
! <Configuration Name="$cfgname|Win32" OutputDirectory=".\\$cfgname\\$self->{name}" IntermediateDirectory=".\\$cfgname\\$self->{name}"
! ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2" WholeProgramOptimization="$p->{wholeopt}">
! <Tool Name="VCCLCompilerTool" Optimization="$p->{opt}"
AdditionalIncludeDirectories="src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{solution}->{options}->{pthread};$self->{includes}"
! PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
! StringPooling="$p->{strpool}"
! RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
EOF
print $f <<EOF;
! AssemblerOutput="0" AssemblerListingLocation=".\\$cfgname\\$self->{name}\\" ObjectFile=".\\$cfgname\\$self->{name}\\"
! ProgramDataBaseFileName=".\\$cfgname\\$self->{name}\\" BrowseInformation="0"
WarningLevel="3" SuppressStartupBanner="TRUE" DebugInformationFormat="3" CompileAs="0"/>
! <Tool Name="VCLinkerTool" OutputFile=".\\$cfgname\\$self->{name}\\$self->{name}.$self->{type}"
! AdditionalDependencies="$libs"
LinkIncremental="0" SuppressStartupBanner="TRUE" AdditionalLibraryDirectories="" IgnoreDefaultLibraryNames="libc"
StackReserveSize="4194304" DisableSpecificWarnings="$self->{disablewarnings}"
! GenerateDebugInformation="TRUE" ProgramDatabaseFile=".\\$cfgname\\$self->{name}\\$self->{name}.pdb"
! GenerateMapFile="FALSE" MapFileName=".\\$cfgname\\$self->{name}\\$self->{name}.map"
SubSystem="1" TargetMachine="1"
EOF
if ($self->{implib}) {
! my $l = $self->{implib};
! $l =~ s/__CFGNAME__/$cfgname/g;
! print $f "\t\tImportLibrary=\"$l\"\n";
}
if ($self->{def}) {
! my $d = $self->{def};
! $d =~ s/__CFGNAME__/$cfgname/g;
! print $f "\t\tModuleDefinitionFile=\"$d\"\n";
}
print $f "\t/>\n";
! print $f "\t<Tool Name=\"VCLibrarianTool\" OutputFile=\".\\$cfgname\\$self->{name}\\$self->{name}.lib\" IgnoreDefaultLibraryNames=\"libc\" />\n";
print $f "\t<Tool Name=\"VCResourceCompilerTool\" AdditionalIncludeDirectories=\"src\\include\" />\n";
if ($self->{builddef}) {
! print $f "\t<Tool Name=\"VCPreLinkEventTool\" Description=\"Generate DEF file\" CommandLine=\"perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name}\" />\n";
}
print $f <<EOF;
</Configuration>
EOF
}
Index: src/tools/msvc/Solution.pm
===================================================================
RCS file: c:/prog/cvsrepo/pgsql/pgsql/src/tools/msvc/Solution.pm,v
retrieving revision 1.1
diff -c -r1.1 Solution.pm
*** src/tools/msvc/Solution.pm 4 Sep 2006 21:30:39 -0000 1.1
--- src/tools/msvc/Solution.pm 14 Sep 2006 08:12:24 -0000
***************
*** 21,28 ****
# Special case - if config.pl has changed, always return 1
sub IsNewer {
my ($newfile, $oldfile) = @_;
! if ($oldfile ne 'vcbuild\config.pl') {
! return 1 if IsNewer($newfile, 'vcbuild\config.pl');
}
return 1 if (!(-e $newfile));
my @nstat = stat($newfile);
--- 21,28 ----
# Special case - if config.pl has changed, always return 1
sub IsNewer {
my ($newfile, $oldfile) = @_;
! if ($oldfile ne 'src\tools\msvc\config.pl') {
! return 1 if IsNewer($newfile, 'src\tools\msvc\config.pl');
}
return 1 if (!(-e $newfile));
my @nstat = stat($newfile);
***************
*** 177,182 ****
--- 177,193 ----
chdir('..\..\..');
}
+ if (IsNewer('src\interfaces\ecpg\include\ecpg_config.h', 'src\interfaces\ecpg\include\ecpg_config.h.in')) {
+ print "Generating ecpg_config.h...\n";
+ open(O,'>','src\interfaces\ecpg\include\ecpg_config.h') || confess "Could not open ecpg_config.h";
+ print O <<EOF;
+ #if (_MSC_VER > 1200)
+ #define HAVE_LONG_LONG_INT_64
+ #endif
+ EOF
+ close(O);
+ }
+
unless (-f "src\\port\\pg_config_paths.h") {
print "Generating pg_config_paths.h...\n";
open(O,'>', 'src\port\pg_config_paths.h') || confess "Could not open pg_config_paths.h";
***************
*** 271,276 ****
--- 282,288 ----
print SLN <<EOF;
$proj->{guid}.Debug|Win32.ActiveCfg = Debug|Win32
$proj->{guid}.Debug|Win32.Build.0 = Debug|Win32
+ $proj->{guid}.Release|Win32.ActiveCfg = Release|Win32
$proj->{guid}.Release|Win32.Build.0 = Release|Win32
EOF
}
Index: src/tools/msvc/build.bat
===================================================================
RCS file: c:/prog/cvsrepo/pgsql/pgsql/src/tools/msvc/build.bat,v
retrieving revision 1.1
diff -c -r1.1 build.bat
*** src/tools/msvc/build.bat 4 Sep 2006 21:30:39 -0000 1.1
--- src/tools/msvc/build.bat 13 Sep 2006 15:04:54 -0000
***************
*** 1,12 ****
! @echo off
! SET STARTDIR=%CD%
!
! perl mkvcbuild.pl
! if errorlevel 1 goto :eof
!
! if exist ..\vcbuild if exist ..\src cd ..
!
! if "%1" == "" msbuild pgsql.sln
! if not "%1" == "" vcbuild %1.vcproj
!
! cd %STARTDIR%
--- 1,18 ----
! @echo off
! SET STARTDIR=%CD%
!
! perl mkvcbuild.pl
! if errorlevel 1 goto :eof
!
! if exist ..\msvc if exist ..\..\..\src cd ..\..\..
! SET CONFIG=
! if "%1" == "" set CONFIG=Debug
! if "%CONFIG%" == "" if "%1" == "DEBUG" set CONFIG=Debug
! if "%CONFIG%" == "" if "%1" == "RELEASE" set CONFIG=Release
! if not "%CONFIG%" == "" shift
! if "%CONFIG%" == "" set CONFIG=Debug
!
! if "%1" == "" msbuild pgsql.sln /p:Configuration=%CONFIG%
! if not "%1" == "" vcbuild %1.vcproj %CONFIG%
!
! cd %STARTDIR%
Index: src/tools/msvc/mkvcbuild.pl
===================================================================
RCS file: c:/prog/cvsrepo/pgsql/pgsql/src/tools/msvc/mkvcbuild.pl,v
retrieving revision 1.1
diff -c -r1.1 mkvcbuild.pl
*** src/tools/msvc/mkvcbuild.pl 4 Sep 2006 21:30:40 -0000 1.1
--- src/tools/msvc/mkvcbuild.pl 14 Sep 2006 09:52:19 -0000
***************
*** 5,16 ****
use Project;
use Solution;
! chdir('..') if (-d '..\vcbuild' && -d '..\src');
! die 'Must run from root directory or vcbuild directory' unless (-d 'vcbuild' && -d 'src');
! die 'Could not find config.pl' unless (-f 'vcbuild/config.pl');
our $config;
! require 'vcbuild/config.pl';
my $solution = new Solution($config);
--- 5,16 ----
use Project;
use Solution;
! chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
! die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
! die 'Could not find config.pl' unless (-f 'src/tools/msvc/config.pl');
our $config;
! require 'src/tools/msvc/config.pl';
my $solution = new Solution($config);
***************
*** 79,84 ****
--- 79,85 ----
$libpq->AddDefine('FRONTEND');
$libpq->AddIncludeDir('src\port');
$libpq->AddLibrary('wsock32.lib');
+ $libpq->AddLibrary('wldap32.lib') if ($solution->{options}->{ldap});
$libpq->UseDef('src\interfaces\libpq\libpqdll.def');
$libpq->ReplaceFile('src\interfaces\libpq\libpqrc.c','src\interfaces\libpq\libpq.rc');
***************
*** 188,195 ****
$proj->AddIncludeDir('src\bin\psql');
$proj->AddReference($libpq,$libpgport);
$proj->AddResourceFile('src\bin\scripts','PostgreSQL Utility');
- $proj->AddLibrary('debug\libpgport\libpgport.lib');
- $proj->AddLibrary('debug\libpq\libpq.lib');
}
$/ = $t;
--- 189,194 ----
***************
*** 224,234 ****
$p->AddDir('src\bin\\' . $n);
$p->AddDefine('FRONTEND');
$p->AddReference($libpgport);
- $p->AddLibrary('debug\libpgport\libpgport.lib');
if ($uselibpq) {
$p->AddIncludeDir('src\interfaces\libpq');
$p->AddReference($libpq);
- $p->AddLibrary('debug\libpq\libpq.lib');
}
return $p;
}
--- 223,231 ----