Review of VS 2010 support patches

Started by Craig Ringerover 14 years ago41 messages
#1Craig Ringer
craig@postnewspapers.com.au

Hi all

I've got through a review of the VS 2010 support patches. Between work
being busy and some interesting issues getting my 64-bit build
environment set up it took longer than anticipated. Sorry.

It looks good so far. I haven't had any reply to my email to Brar, so
there are a few details (like whether x64 builds were tested and how x64
required libraries were built) I could use, but what I've got done so
far seems fine.

Details follow.

PATCH FORMATTING
==================

The patch (VS2010v7.patch) seems to mix significant changes with
whitespace fixes etc. These should be separated for clarity and ease of
future bisect testing etc. Any "perltidy" run should be done as a
separate patch, too. This is easy if you are using git, because you can
just commit each to your local tree then use git format-patch to produce
nice patches. If you have a local tree with a more complicated history,
you can use git rebase to tidy up the history before you format-patch.

The patches apply cleanly to git master as of
21f1e15aafb13ab2430e831a3da7d4d4f525d1ce .

pgflex.pl and pgbison.pl
=====================

pgflex.pl and pgbison.pl are a big improvement over the horrid batch
files, but are perhaps too little a translation. There's no need for the
big if(string) then (otherstring) stuff; it can be done much more
cleanly by storing a simple hash of paths to options and doing a file
extension substitution to generate the output filenames. The hash only
needs to be populated for files that get processed with non-default
options, so for pgflex all you need is:

%LEX_OPTS = { 'src\backend\parser\scan.c' -> '-CF' };

I can send adjusted versions of pgflex.pl and pgbison.pl that

DOCUMENTATION
===============

I didn't notice any documentation updates to reflect the fact that
Visual Studio 2010 is now supported. It'd be a good idea to change
install-windows-full.html (or the source of it, anyway) to mention VS
2010 support.

TEST RESULTS (x86)
=================

I used a buildenv.pl and config.pl that's known to build under VS 2008
and pass "vcregress check" with an unpatched copy of git master. I built
with everything except uuid and tcl enabled; I'll see if I can add them
later.

The patches applied cleanly, and didn't break VS 2008 builds, which
continued to work fine after a "clean dist" and "build". "vcregress
check" still passes.

Builds done with VS 2010 using the patches worked fine, and passed
"vcregress check" tests.

I should have plcheck and contribcheck results as soon as I've got
things rebuilt with uuid and tcl.

TEST RESULTS (x64)
=================

I'm still working on 64-bit tests. I've finally found out how to get
64-bit compilation working under Visual Studio 2008 Express Edition (or,
rather, Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1)
so I'll be testing that shortly.

I'm not sure if I'll be able to get 64-bit copies of all the optional
libraries built, so it may be a more minimal build. It'll include at
least zlib, plperl and plpython 64-bit support, though. Information from
Briar about whether he built for 64-bit and if so how he got his
libraries built would help.

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088 Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

#2Brar Piening
brar@gmx.de
In reply to: Craig Ringer (#1)
Re: Review of VS 2010 support patches

-------- Original Message --------
Subject: Review of VS 2010 support patches
From: Craig Ringer <craig@postnewspapers.com.au>
To: PG Hackers <pgsql-hackers@postgresql.org>, Brar Piening <brar@gmx.de>
Date: 05.07.2011 14:25

I haven't had any reply to my email to Brar, so there are a few
details (like whether x64 builds were tested and how x64 required
libraries were built) I could use, but what I've got done so far seems
fine.

I've replied on-list see:
http://archives.postgresql.org/pgsql-hackers/2011-07/msg00066.php

Seems like i've got fooled by "reply to list" being thunderbird's
default for mailing lists once more. Sorry for that one.

The patch (VS2010v7.patch) seems to mix significant changes with
whitespace fixes etc.

Current version (VS2010v8.patch) which I've submitted on-list about one
month ago has fixed this as per Tom Lane's comment.
See: http://archives.postgresql.org/message-id/4DEDB6EE.9060307@gmx.de

pgflex.pl and pgbison.pl
=====================

pgflex.pl and pgbison.pl are a big improvement over the horrid batch
files, but are perhaps too little a translation. There's no need for
the big if(string) then (otherstring) stuff; it can be done much more
cleanly by storing a simple hash of paths to options and doing a file
extension substitution to generate the output filenames. The hash only
needs to be populated for files that get processed with non-default
options, so for pgflex all you need is:

%LEX_OPTS = { 'src\backend\parser\scan.c' -> '-CF' };

I can send adjusted versions of pgflex.pl and pgbison.pl that

I think the approach Andrew Dunstan chose (parsing the Makefiles) is
even more flexible and future proof. We should probably be using his
versions.
See: http://archives.postgresql.org/pgsql-hackers/2011-07/msg00140.php
and http://archives.postgresql.org/pgsql-hackers/2011-07/msg00185.php

DOCUMENTATION
===============

I didn't notice any documentation updates to reflect the fact that
Visual Studio 2010 is now supported. It'd be a good idea to change
install-windows-full.html (or the source of it, anyway) to mention VS
2010 support.

Yep - a clear leftover. I've never written any SGML but I'll try to come
up with something as soon as as I've got the doc build working on my system.

I'm not sure if I'll be able to get 64-bit copies of all the optional
libraries built, so it may be a more minimal build. It'll include at
least zlib, plperl and plpython 64-bit support, though. Information
from Briar about whether he built for 64-bit and if so how he got his
libraries built would help.

Actually my default builds are 64-bit builds as my PC is Win7 x64 and
I'm using 64-Bit versions for my PostgreSQL work.
As you noted, the availability of 64-bit libraries was the limiting
factor for more extensive testing but I haven't run into any Problems
with my default configuration (nothing but plperl) and some others I've
tried yet.

Regards,

Brar

#3Craig Ringer
craig@postnewspapers.com.au
In reply to: Brar Piening (#2)
Re: Review of VS 2010 support patches

On 6/07/2011 2:15 AM, Brar Piening wrote:

I've replied on-list see:
http://archives.postgresql.org/pgsql-hackers/2011-07/msg00066.php

Ah, sorry I missed that. I generally can't keep up with -hackers and
have to rely on being cc'd.

The patch (VS2010v7.patch) seems to mix significant changes with
whitespace fixes etc.

Current version (VS2010v8.patch) which I've submitted on-list about one
month ago has fixed this as per Tom Lane's comment.
See: http://archives.postgresql.org/message-id/4DEDB6EE.9060307@gmx.de

That's what threw me, actually. The patch is named
"perltidy_before.patch"; I didn't see a separate VS2010v8.patch or link
to one and was trying to figure out how perltidy_before.patch related to
VS2010v7.patch .

It turns out that VS2010v8.patch is also attached to the same message.
Not that you'd know it from the ... interesting ... way the web ui
presents attachments. Sorry I missed it.

I think the approach Andrew Dunstan chose (parsing the Makefiles) is
even more flexible and future proof. We should probably be using his
versions.
See: http://archives.postgresql.org/pgsql-hackers/2011-07/msg00140.php
and http://archives.postgresql.org/pgsql-hackers/2011-07/msg00185.php

That makes sense. Do you want to integrate those in a v9 revision along
wiht a docs patch?

For the docs, it might be worth being more specific about the visual
studio versions. Instead of:

"PostgreSQL supports the compilers from Visual Studio 2005 and Visual
Studio 2008. When using the Platform SDK only, or when building for
64-bit Windows, only Visual Studio 2008 is supported."

I'd suggest writing:

"PostgreSQL supports compilation the compilers shipped with Visual
Studio 2005, 2008 and 2010 (including Express editions), as well as
standalone Windows SDK releases 6.0 to 7.1. Only 32-bit PostgreSQL
builds are supported with SDK versions prior to 6.1 and Visual Studio
versions prior to 2008."

Additionally, it might be worth expanding on "If you wish to build a
64-bit version, you must use the 64-bit version of the command, and vice
versa".

The free SDKs don't install both 32-bit and 64-bit environment start
menu items; they seem to just pick the local host architecture. My 7.1
SDK only has a start menu launcher for x64. So: Perhaps it's worth
mentioning that the "setenv" command can be used from within a Windows
SDK shell to switch architectures. "setenv /?" produces help. For Visual
Studio, use \VC\vcvarsall.bat in your Visual Studio installation
directory. See:
http://msdn.microsoft.com/en-us/library/x4d2c09s(v=VS.100).aspx

Actually my default builds are 64-bit builds as my PC is Win7 x64 and
I'm using 64-Bit versions for my PostgreSQL work.

Ah, OK. Good to know.

I had no problems doing an x64 build using the Windows SDK version 7.1,
and tests passed fine.

Now I just need to test with Windows SDK 6.0 (if I can even get it to
install on win7 x64; the installer keeps crashing) as that's the SDK
shipped with Visual Studio 2005 SP1 .

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088 Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

#4Brar Piening
brar@gmx.de
In reply to: Craig Ringer (#3)
Re: Review of VS 2010 support patches

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Craig Ringer <craig@postnewspapers.com.au>
To: Brar Piening <brar@gmx.de>
Date: 06.07.2011 14:56

It turns out that VS2010v8.patch is also attached to the same message.
Not that you'd know it from the ... interesting ... way the web ui
presents attachments. Sorry I missed it.

Yes I've also noticed that the web ui has somewhat screwed up the two
patches attached to my email.

This seems avoidable as one can see in
http://archives.postgresql.org/pgsql-hackers/2011-07/msg00140.php but I
don't know how.

[...]

That makes sense. Do you want to integrate those in a v9 revision
along wiht a docs patch?

I certainly could. But as those files are Andrew's work which isn't
really related to VS2010 build and could as well be commited seperately
I don't want to take credit for it.
I'll remove my versions from the patch (v9 probably) if those files get
commited.

[...]

For the docs, it might be worth being more specific about the visual
studio versions.

[...]

Thanks for the hints I'll consider then once I'll get started with the docs.

[...]

Now I just need to test with Windows SDK 6.0 (if I can even get it to
install on win7 x64; the installer keeps crashing) as that's the SDK
shipped with Visual Studio 2005 SP1 .

Actually I've also successfully tested an empty (no config.pl) 32-bit
build using Visual Studio 2005 RTM.

Regards,

Brar

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#4)
Re: Review of VS 2010 support patches

On 07/06/2011 04:41 PM, Brar Piening wrote:

I certainly could. But as those files are Andrew's work which isn't
really related to VS2010 build and could as well be commited
seperately I don't want to take credit for it.
I'll remove my versions from the patch (v9 probably) if those files
get commited.

I'm just doing some final testing and preparing to commit the new pgflex
and pgbison.

cheers

andrew

#6Brar Piening
brar@gmx.de
In reply to: Andrew Dunstan (#5)
2 attachment(s)
Re: Review of VS 2010 support patches

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan <andrew@dunslane.net>
To: Brar Piening <brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files
get commited.

I'm just doing some final testing and preparing to commit the new
pgflex and pgbison.

The attached patch includes documentation changes and excludes my
versions of pgbison.pl and pgflex.pl which have been replaced by
Andrews' versions that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

Regards,

Brar

PS: Just in case the web ui concatenates the two patch files again:
perltidy_before.patch has 518 lines with the last line of code being "my
$status = $? >>8;" and VS2010v9.patch has 1608 lines with the last line
of code being "if exist src\backend\win32ver.rc del /q
src\backend\win32ver.rc"

Attachments:

perltidy_before.patchtext/plain; name=perltidy_before.patchDownload
diff -Napcdr -x .git postgresql/src/tools/msvc/Install.pm postgresql_dev/src/tools/msvc/Install.pm
*** postgresql/src/tools/msvc/Install.pm	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/Install.pm	Wed Jul  6 23:36:56 2011
*************** sub Install
*** 56,65 ****
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories($target, 'bin', 'lib', 'share', 'share/timezonesets',
!                       'share/extension', 'share/contrib',
!                       'doc', 'doc/extension', 'doc/contrib',
!                       'symbols', 'share/tsearch_data');
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
--- 56,66 ----
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories(
!         $target, 'bin', 'lib', 'share',
!         'share/timezonesets','share/extension', 'share/contrib','doc',
!         'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
!     );
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
*************** sub Install
*** 113,123 ****
      CopyContribFiles($config,$target);
      CopyIncludeFiles($target);
  
! 	my $pl_extension_files = [];
! 	my @pldirs = ('src/pl/plpgsql/src');
! 	push @pldirs,"src/pl/plperl" if $config->{perl};
! 	push @pldirs,"src/pl/plpython" if $config->{python};
! 	push @pldirs,"src/pl/tcl" if $config->{tcl};
      File::Find::find(
          {
              wanted =>sub {
--- 114,124 ----
      CopyContribFiles($config,$target);
      CopyIncludeFiles($target);
  
!     my $pl_extension_files = [];
!     my @pldirs = ('src/pl/plpgsql/src');
!     push @pldirs,"src/pl/plperl" if $config->{perl};
!     push @pldirs,"src/pl/plpython" if $config->{python};
!     push @pldirs,"src/pl/tcl" if $config->{tcl};
      File::Find::find(
          {
              wanted =>sub {
*************** sub Install
*** 127,136 ****
          },
          @pldirs
      );
!     CopySetOfFiles(
!         'PL Extension files', $pl_extension_files,
!         $target . '/share/extension/'
!     );
  
      GenerateNLSFiles($target,$config->{nls},$majorver) if ($config->{nls});
  
--- 128,134 ----
          },
          @pldirs
      );
!     CopySetOfFiles('PL Extension files', $pl_extension_files,$target . '/share/extension/');
  
      GenerateNLSFiles($target,$config->{nls},$majorver) if ($config->{nls});
  
*************** sub CopyContribFiles
*** 350,358 ****
  
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy('contrib/' . $d . '/' . $f . '.control',
!                       $target . '/share/extension/' . $f . '.control')
!                   || croak("Could not copy file $f.control in contrib $d");
                  print '.';
              }
          }
--- 348,357 ----
  
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy(
!                     'contrib/' . $d . '/' . $f . '.control',
!                     $target . '/share/extension/' . $f . '.control'
!                 )|| croak("Could not copy file $f.control in contrib $d");
                  print '.';
              }
          }
*************** sub CopyContribFiles
*** 369,375 ****
              foreach my $f (split /\s+/,$flist)
              {
                  lcopy('contrib/' . $d . '/' . $f,
!                       $target . '/share/' . $moduledir . '/' . basename($f))
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
--- 368,374 ----
              foreach my $f (split /\s+/,$flist)
              {
                  lcopy('contrib/' . $d . '/' . $f,
!                     $target . '/share/' . $moduledir . '/' . basename($f))
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
*************** sub CopyContribFiles
*** 383,390 ****
  
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy('contrib/' . $d . '/' . $f,
!                       $target . '/share/tsearch_data/' . basename($f))
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
--- 382,388 ----
  
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy('contrib/' . $d . '/' . $f,$target . '/share/tsearch_data/' . basename($f))
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
*************** sub CopyContribFiles
*** 402,409 ****
                if ($d eq 'spi');
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy('contrib/' . $d . '/' . $f,
!                       $target . '/doc/' . $moduledir . '/' . $f)
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
--- 400,406 ----
                if ($d eq 'spi');
              foreach my $f (split /\s+/,$flist)
              {
!                 lcopy('contrib/' . $d . '/' . $f,$target . '/doc/' . $moduledir . '/' . $f)
                    || croak("Could not copy file $f in contrib $d");
                  print '.';
              }
*************** sub CopyIncludeFiles
*** 473,486 ****
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/',
!               'src/backend/parser/', 'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
  
! 	# some xcopy progs don't like mixed slash style paths
! 	(my $ctarget = $target) =~ s!/!\\!g;
      while (my $d = readdir($D))
      {
          next if ($d =~ /^\./);
--- 470,483 ----
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
!         'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
  
!     # some xcopy progs don't like mixed slash style paths
!     (my $ctarget = $target) =~ s!/!\\!g;
      while (my $d = readdir($D))
      {
          next if ($d =~ /^\./);
diff -Napcdr -x .git postgresql/src/tools/msvc/Mkvcbuild.pm postgresql_dev/src/tools/msvc/Mkvcbuild.pm
*** postgresql/src/tools/msvc/Mkvcbuild.pm	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/Mkvcbuild.pm	Wed Jul  6 23:36:56 2011
*************** sub mkvcbuild
*** 172,177 ****
--- 172,178 ----
  
      if ($solution->{options}->{python})
      {
+ 
          # Attempt to get python version and location.
          # Assume python.exe in specified dir.
          open(P,
*************** sub mkvcbuild
*** 190,197 ****
            if (!(defined($pyprefix) && defined($pyver)));
  
          my $pymajorver = substr($pyver, 0, 1);
!         my $plpython = $solution->AddProject('plpython' . $pymajorver, 'dll',
!                                              'PLs', 'src\pl\plpython');
          $plpython->AddIncludeDir($pyprefix . '\include');
          $plpython->AddLibrary($pyprefix . "\\Libs\\python$pyver.lib");
          $plpython->AddReference($postgres);
--- 191,198 ----
            if (!(defined($pyprefix) && defined($pyver)));
  
          my $pymajorver = substr($pyver, 0, 1);
!         my $plpython =
!           $solution->AddProject('plpython' . $pymajorver, 'dll','PLs', 'src\pl\plpython');
          $plpython->AddIncludeDir($pyprefix . '\include');
          $plpython->AddLibrary($pyprefix . "\\Libs\\python$pyver.lib");
          $plpython->AddReference($postgres);
diff -Napcdr -x .git postgresql/src/tools/msvc/Solution.pm postgresql_dev/src/tools/msvc/Solution.pm
*** postgresql/src/tools/msvc/Solution.pm	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/Solution.pm	Wed Jul  6 23:36:57 2011
*************** s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x)
*** 273,295 ****
          );
      }
  
!     if ($self->{options}->{python} && IsNewer('src\pl\plpython\spiexceptions.h','src\include\backend\errcodes.txt'))
      {
          print "Generating spiexceptions.h...\n";
!         system('perl src\pl\plpython\generate-spiexceptions.pl src\backend\utils\errcodes.txt > src\pl\plpython\spiexceptions.h');
      }
  
      if (IsNewer('src\include\utils\errcodes.h','src\backend\utils\errcodes.txt'))
      {
          print "Generating errcodes.h...\n";
!         system('perl src\backend\utils\generate-errcodes.pl src\backend\utils\errcodes.txt > src\backend\utils\errcodes.h');
          copyFile('src\backend\utils\errcodes.h','src\include\utils\errcodes.h');
      }
  
      if (IsNewer('src\pl\plpgsql\src\plerrcodes.h','src\backend\utils\errcodes.txt'))
      {
          print "Generating plerrcodes.h...\n";
!         system('perl src\pl\plpgsql\src\generate-plerrcodes.pl src\backend\utils\errcodes.txt > src\pl\plpgsql\src\plerrcodes.h');
      }
  
      if (IsNewer('src\interfaces\libpq\libpq.rc','src\interfaces\libpq\libpq.rc.in'))
--- 273,302 ----
          );
      }
  
!     if ($self->{options}->{python}
!         && IsNewer('src\pl\plpython\spiexceptions.h','src\include\backend\errcodes.txt'))
      {
          print "Generating spiexceptions.h...\n";
!         system(
! 'perl src\pl\plpython\generate-spiexceptions.pl src\backend\utils\errcodes.txt > src\pl\plpython\spiexceptions.h'
!         );
      }
  
      if (IsNewer('src\include\utils\errcodes.h','src\backend\utils\errcodes.txt'))
      {
          print "Generating errcodes.h...\n";
!         system(
! 'perl src\backend\utils\generate-errcodes.pl src\backend\utils\errcodes.txt > src\backend\utils\errcodes.h'
!         );
          copyFile('src\backend\utils\errcodes.h','src\include\utils\errcodes.h');
      }
  
      if (IsNewer('src\pl\plpgsql\src\plerrcodes.h','src\backend\utils\errcodes.txt'))
      {
          print "Generating plerrcodes.h...\n";
!         system(
! 'perl src\pl\plpgsql\src\generate-plerrcodes.pl src\backend\utils\errcodes.txt > src\pl\plpgsql\src\plerrcodes.h'
!         );
      }
  
      if (IsNewer('src\interfaces\libpq\libpq.rc','src\interfaces\libpq\libpq.rc.in'))
diff -Napcdr -x .git postgresql/src/tools/msvc/builddoc.pl postgresql_dev/src/tools/msvc/builddoc.pl
*** postgresql/src/tools/msvc/builddoc.pl	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/builddoc.pl	Wed Jul  6 23:36:56 2011
*************** use strict;
*** 9,15 ****
  use File::Copy;
  use Cwd qw(abs_path getcwd);
  
- 
  my $startdir =  getcwd();
  
  my $openjade = 'openjade-1.3.1';
--- 9,14 ----
*************** die "bad DOCROOT '$docroot'" unless ($do
*** 27,44 ****
  my @notfound;
  foreach my $dir ('docbook', $openjade, $dsssl)
  {
!    push(@notfound,$dir) unless -d "$docroot/$dir";
  }
  missing() if @notfound;
  
  my $arg = shift;
  renamefiles();
  
- 
  chdir 'doc/src/sgml';
  
! $ENV{SGML_CATALOG_FILES} = "$docroot/$openjade/dsssl/catalog;" . 
! 				"$docroot/docbook/docbook.cat";
  
  my $cmd;
  
--- 26,41 ----
  my @notfound;
  foreach my $dir ('docbook', $openjade, $dsssl)
  {
!     push(@notfound,$dir) unless -d "$docroot/$dir";
  }
  missing() if @notfound;
  
  my $arg = shift;
  renamefiles();
  
  chdir 'doc/src/sgml';
  
! $ENV{SGML_CATALOG_FILES} = "$docroot/$openjade/dsssl/catalog;" ."$docroot/docbook/docbook.cat";
  
  my $cmd;
  
*************** my $cmd;
*** 46,86 ****
  # can't die on "failure"
  
  $cmd =
! "perl mk_feature_tables.pl YES " .
! 	"../../../src/backend/catalog/sql_feature_packages.txt " .
! 	"../../../src/backend/catalog/sql_features.txt " .
! 	"> features-supported.sgml";
! system($cmd); die "features_supported" if $?;
! $cmd =
! "perl mk_feature_tables.pl NO " .
! 	"\"../../../src/backend/catalog/sql_feature_packages.txt\" " .
! 	"\"../../../src/backend/catalog/sql_features.txt\" " .
! 	"> features-unsupported.sgml";
! system($cmd); die "features_unsupported" if $?;
  $cmd =
! "perl generate-errcodes-table.pl \"../../../src/backend/utils/errcodes.txt\" " .
! 	"> errcodes-table.sgml";
! system($cmd); die "errcodes-table" if $?;
  
  print "Running first build...\n";
  $cmd =
! "\"$docroot/$openjade/bin/openjade\" -V html-index -wall " .
! 	"-wno-unused-param -wno-empty -D . -c \"$docroot/$dsssl/catalog\" " .
! 	"-d stylesheet.dsl -i output-html -t sgml postgres.sgml 2>&1 " .
! 	"| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd =
! "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex " .
! 	"-o bookindex.sgml HTML.index";
! system($cmd); die "collateindex" if $?;
  mkdir "html";
  print "Running second build...\n";
  $cmd =
! "\"$docroot/$openjade/bin/openjade\" -wall -wno-unused-param -wno-empty " .
! 	"-D . -c \"$docroot/$dsssl/catalog\" -d stylesheet.dsl -t sgml " .
! 	"-i output-html -i include-index postgres.sgml 2>&1 " .
! 	"| findstr /V \"DTDDECL catalog entries are not supported\" ";
  
  system($cmd); # die "openjade" if $?;
  
--- 43,85 ----
  # can't die on "failure"
  
  $cmd =
!    "perl mk_feature_tables.pl YES "
!   ."../../../src/backend/catalog/sql_feature_packages.txt "
!   ."../../../src/backend/catalog/sql_features.txt "
!   ."> features-supported.sgml";
! system($cmd);
! die "features_supported" if $?;
  $cmd =
!    "perl mk_feature_tables.pl NO "
!   ."\"../../../src/backend/catalog/sql_feature_packages.txt\" "
!   ."\"../../../src/backend/catalog/sql_features.txt\" "
!   ."> features-unsupported.sgml";
! system($cmd);
! die "features_unsupported" if $?;
! $cmd ="perl generate-errcodes-table.pl \"../../../src/backend/utils/errcodes.txt\" "
!   ."> errcodes-table.sgml";
! system($cmd);
! die "errcodes-table" if $?;
  
  print "Running first build...\n";
  $cmd =
!    "\"$docroot/$openjade/bin/openjade\" -V html-index -wall "
!   ."-wno-unused-param -wno-empty -D . -c \"$docroot/$dsssl/catalog\" "
!   ."-d stylesheet.dsl -i output-html -t sgml postgres.sgml 2>&1 "
!   ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
!   ."-o bookindex.sgml HTML.index";
! system($cmd);
! die "collateindex" if $?;
  mkdir "html";
  print "Running second build...\n";
  $cmd =
!    "\"$docroot/$openjade/bin/openjade\" -wall -wno-unused-param -wno-empty "
!   ."-D . -c \"$docroot/$dsssl/catalog\" -d stylesheet.dsl -t sgml "
!   ."-i output-html -i include-index postgres.sgml 2>&1 "
!   ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  
  system($cmd); # die "openjade" if $?;
  
*************** exit;
*** 94,122 ****
  
  sub renamefiles
  {
! 	# Rename ISO entity files
! 	my $savedir = getcwd();
! 	chdir "$docroot/docbook";
! 	foreach my $f (glob('ISO*'))
! 	{
! 		next if $f =~ /\.gml$/i;	
! 		my $nf = $f;
! 		$nf =~ s/ISO(.*)/ISO-$1.gml/;
! 		move $f, $nf;
! 	}
! 	chdir $savedir;
! 		
  }
  
  sub missing
  {
! 	print STDERR "could not find $docroot/$_\n" foreach (@notfound);
! 	exit 1;
  }
  
  sub noversion
  {
! 	print STDERR "Could not find version.sgml. ",
! 		"Please run mkvcbuild.pl first!\n";
! 	exit 1;
  }
--- 93,121 ----
  
  sub renamefiles
  {
! 
!     # Rename ISO entity files
!     my $savedir = getcwd();
!     chdir "$docroot/docbook";
!     foreach my $f (glob('ISO*'))
!     {
!         next if $f =~ /\.gml$/i;
!         my $nf = $f;
!         $nf =~ s/ISO(.*)/ISO-$1.gml/;
!         move $f, $nf;
!     }
!     chdir $savedir;
! 
  }
  
  sub missing
  {
!     print STDERR "could not find $docroot/$_\n" foreach (@notfound);
!     exit 1;
  }
  
  sub noversion
  {
!     print STDERR "Could not find version.sgml. ","Please run mkvcbuild.pl first!\n";
!     exit 1;
  }
diff -Napcdr -x .git postgresql/src/tools/msvc/vcregress.pl postgresql_dev/src/tools/msvc/vcregress.pl
*** postgresql/src/tools/msvc/vcregress.pl	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/vcregress.pl	Wed Jul  6 23:36:56 2011
*************** my %command = (
*** 72,78 ****
      INSTALLCHECK => \&installcheck,
      ECPGCHECK => \&ecpgcheck,
      CONTRIBCHECK => \&contribcheck,
! 	ISOLATIONCHECK => \&isolationcheck,
  );
  
  my $proc = $command{$what};
--- 72,78 ----
      INSTALLCHECK => \&installcheck,
      ECPGCHECK => \&ecpgcheck,
      CONTRIBCHECK => \&contribcheck,
!     ISOLATIONCHECK => \&isolationcheck,
  );
  
  my $proc = $command{$what};
*************** sub ecpgcheck
*** 140,153 ****
  
  sub isolationcheck
  {
! 	chdir "../isolation";
! 	copy("../../../$Config/isolationtester/isolationtester.exe",".");
      my @args = (
! 				"../../../$Config/pg_isolation_regress/pg_isolation_regress",
! 				"--psqldir=../../../$Config/psql",
! 				"--inputdir=.",  
! 				"--schedule=./isolation_schedule"
! 			   );
      push(@args,$maxconn) if $maxconn;
      system(@args);
      my $status = $? >>8;
--- 140,152 ----
  
  sub isolationcheck
  {
!     chdir "../isolation";
!     copy("../../../$Config/isolationtester/isolationtester.exe",".");
      my @args = (
!         "../../../$Config/pg_isolation_regress/pg_isolation_regress",
!         "--psqldir=../../../$Config/psql",
!         "--inputdir=.","--schedule=./isolation_schedule"
!     );
      push(@args,$maxconn) if $maxconn;
      system(@args);
      my $status = $? >>8;
VS2010v9.patchtext/plain; name=VS2010v9.patchDownload
diff -Napcdr -x .git postgresql/doc/src/sgml/install-windows.sgml postgresql_dev/doc/src/sgml/install-windows.sgml
*** postgresql/doc/src/sgml/install-windows.sgml	Tue Jul  5 05:55:17 2011
--- postgresql_dev/doc/src/sgml/install-windows.sgml	Wed Jul  6 22:40:51 2011
***************
*** 20,29 ****
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Platform SDK</productname> and use use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005 or 2008</productname>. In some cases
!   that requires the installation of the <productname>Platform SDK</productname>
    in addition to the compiler.
   </para>
  
--- 20,29 ----
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Windows SDK</productname> and use use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005, 2008 or 2010</productname>. In some cases
!   that requires the installation of the <productname>Windows SDK</productname>
    in addition to the compiler.
   </para>
  
***************
*** 69,100 ****
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Platform SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Platform SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way us to use the compilers in the <productname>Platform SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL supports the compilers from
!   <productname>Visual Studio 2005</productname> and
!   <productname>Visual Studio 2008</productname>. When using the Platform SDK
!   only, or when building for 64-bit Windows, only
!   <productname>Visual Studio 2008</productname> is supported.
!   <productname>Visual Studio 2010</productname> is not yet supported.
!  </para>
! 
!  <para>
!   When building using the <productname>Platform SDK</productname>, versions
!   6.0 to 7.0 of the SDK are supported. Older or newer versions will not work.
!   In particular, versions from 7.0a and later will not work, since
!   they include compilers from <productname>Visual Studio 2010</productname>.
   </para>
  
   <para>
--- 69,94 ----
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Microsoft Windows SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Microsoft Windows SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way is to use the compilers in the <productname>Windows SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL is known to support compilation using the compilers shipped with
!   <productname>Visual Studio 2005</productname> to
!   <productname>Visual Studio 2010</productname> (including Express editions),
!   as well as standalone Windows SDK releases 6.0 to 7.1.
!   64-bit PostgreSQL builds are only supported with
!   <productname>Microsoft Windows SDK</productname> version 6.0a and above or
!   <productname>Visual Studio 2008</productname> and above.
   </para>
  
   <para>
***************
*** 104,114 ****
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>. In the
!   <productname>Platform SDK</productname>, start the
!   <application>CMD shell</application> listed under the SDK on the Start Menu.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
--- 98,110 ----
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
+   In the <productname>Microsoft Windows SDK</productname>, start the
+   <application>CMD shell</application> listed under the SDK on the Start Menu.
+   In recent SDK versions you can change the targeted CPU architecture by using
+   the <command>setenv</command> command.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 148,164 ****
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Platform SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Platform SDK</productname> (currently
!       version 7.0), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Platform SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
--- 144,160 ----
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Windows SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Windows SDK</productname> (currently
!       version 7.1), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Windows SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 202,207 ****
--- 198,207 ----
        Bison can be downloaded from <ulink url="http://gnuwin32.sourceforge.net"></>.
        Flex can be downloaded from
        <ulink url="http://www.postgresql.org/ftp/misc/winflex/"></>.
+       If you are using <productname>msysGit</productname> for accessing the
+       PostgreSQL <productname>Git</productname> repository you probably already
+       have recent versions of bison and flex in your <productname>Git</productname>
+       binary directory.
       </para>
  
       <note>
*************** $ENV{DOCROOT}='c:\docbook';
*** 479,485 ****
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Platform SDK</productname> method is recommended.
   </para>
  
   <para>
--- 479,485 ----
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Windows SDK</productname> method is recommended.
   </para>
  
   <para>
diff -Napcdr -x .git postgresql/src/tools/msvc/Install.pm postgresql_dev/src/tools/msvc/Install.pm
*** postgresql/src/tools/msvc/Install.pm	Wed Jul  6 23:51:59 2011
--- postgresql_dev/src/tools/msvc/Install.pm	Wed Jul  6 23:39:50 2011
*************** sub Install
*** 56,66 ****
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories(
!         $target, 'bin', 'lib', 'share',
!         'share/timezonesets','share/extension', 'share/contrib','doc',
!         'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
!     );
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
--- 56,63 ----
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories($target, 'bin', 'lib', 'share','share/timezonesets','share/extension',
!         'share/contrib','doc','doc/extension', 'doc/contrib','symbols', 'share/tsearch_data');
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
*************** sub CopySolutionOutput
*** 186,191 ****
--- 183,195 ----
      my $rem = qr{Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"\) = "([^"]+)"};
  
      my $sln = read_file("pgsql.sln") || croak "Could not open pgsql.sln\n";
+ 
+     my $vcproj = 'vcproj';
+     if ($sln =~ /Microsoft Visual Studio Solution File, Format Version (\d+)\.\d+/ && $1 >= 11)
+     {
+         $vcproj = 'vcxproj';
+     }
+ 
      print "Copying build output files...";
      while ($sln =~ $rem)
      {
*************** sub CopySolutionOutput
*** 195,220 ****
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.vcproj") || croak "Could not open $pf.vcproj\n";
!         if ($proj !~ qr{ConfigurationType="([^"]+)"})
!         {
!             croak "Could not parse $pf.vcproj\n";
!         }
!         if ($1 == 1)
          {
!             $dir = "bin";
!             $ext = "exe";
          }
!         elsif ($1 == 2)
          {
!             $dir = "lib";
!             $ext = "dll";
          }
          else
          {
! 
!             # Static lib, such as libpgport, only used internally during build, don't install
!             next;
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
--- 199,246 ----
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.$vcproj") || croak "Could not open $pf.$vcproj\n";
!         if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
          {
!             if ($1 == 1)
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 == 2)
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
!         elsif ($vcproj eq 'vcxproj' && $proj =~ qr{<ConfigurationType>(\w+)</ConfigurationType>})
          {
!             if ($1 eq 'Application')
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 eq 'DynamicLibrary')
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else # 'StaticLibrary'
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
          else
          {
!             croak "Could not parse $pf.$vcproj\n";
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
*************** sub CopyIncludeFiles
*** 470,477 ****
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
!         'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
--- 496,502 ----
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/','gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
diff -Napcdr -x .git postgresql/src/tools/msvc/Mkvcbuild.pm postgresql_dev/src/tools/msvc/Mkvcbuild.pm
*** postgresql/src/tools/msvc/Mkvcbuild.pm	Wed Jul  6 23:51:59 2011
--- postgresql_dev/src/tools/msvc/Mkvcbuild.pm	Wed Jul  6 23:39:50 2011
*************** sub mkvcbuild
*** 45,51 ****
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     $solution = new Solution($config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
--- 45,53 ----
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     my $vsVersion = VSObjectFactory::DetermineVisualStudioVersion();
! 
!     $solution = VSObjectFactory::CreateSolution($vsVersion, $config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
*************** sub mkvcbuild
*** 488,493 ****
--- 490,496 ----
      $pgregress->AddReference($libpgport);
  
      $solution->Save();
+     return $solution->{vcver};
  }
  
  #####################
diff -Napcdr -x .git postgresql/src/tools/msvc/Project.pm postgresql_dev/src/tools/msvc/Project.pm
*** postgresql/src/tools/msvc/Project.pm	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/Project.pm	Wed Jul  6 23:39:50 2011
*************** use strict;
*** 10,18 ****
  use warnings;
  use File::Basename;
  
! sub new
  {
!     my ($junk, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
--- 10,18 ----
  use warnings;
  use File::Basename;
  
! sub _new
  {
!     my ($classname, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
*************** sub new
*** 20,43 ****
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name            => $name,
!         type            => $type,
!         guid            => Win32::GuidGen(),
!         files           => {},
!         references      => [],
!         libraries       => [],
!         suffixlib       => [],
!         includes        => '',
!         prefixincludes  => '',
!         defines         => ';',
!         solution        => $solution,
!         disablewarnings => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         vcver           => $solution->{vcver},
!         platform        => $solution->{platform},
      };
  
!     bless $self;
      return $self;
  }
  
--- 20,46 ----
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name                  => $name,
!         type                  => $type,
!         guid                  => Win32::GuidGen(),
!         files                 => {},
!         references            => [],
!         libraries             => [],
!         suffixlib             => [],
!         includes              => '',
!         prefixincludes        => '',
!         defines               => ';',
!         solution              => $solution,
!         disablewarnings       => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
! 
!         # vcver has to be set in derived classes
!         vcver                 => undef,
!         filenameExtension     => '.vcproj',
!         platform              => $solution->{platform},
      };
  
!     bless($self, $classname);
      return $self;
  }
  
*************** sub Save
*** 355,371 ****
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}.vcproj") || croak("Could not write to $self->{name}.vcproj\n");
      $self->WriteHeader(*F);
!     $self->WriteReferences(*F);
!     print F <<EOF;
   <Files>
  EOF
      my @dirstack = ();
      my %uniquefiles;
!     foreach my $f (sort keys %{ $self->{files} })
      {
!         confess "Bad format filename '$f'\n" unless ($f =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
          my $dir = $1;
          my $file = $2;
  
--- 358,407 ----
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}$self->{filenameExtension}")
!       || croak("Could not write to $self->{name}$self->{filenameExtension}\n");
      $self->WriteHeader(*F);
!     $self->WriteFiles(*F);
!     $self->Footer(*F);
!     close(F);
! }
! 
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
! }
! 
! sub WriteFiles
! {
!     my ($self, $f) = @_;
!     print $f <<EOF;
   <Files>
  EOF
      my @dirstack = ();
      my %uniquefiles;
!     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
      {
!         confess "Bad format filename '$fileNameWithPath'\n"
!           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
          my $dir = $1;
          my $file = $2;
  
*************** EOF
*** 377,383 ****
                  last if (length($dir) == length(join('\\',@dirstack)));
                  last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
              }
!             print F ' ' x $#dirstack . "  </Filter>\n";
              pop @dirstack;
          }
  
--- 413,419 ----
                  last if (length($dir) == length(join('\\',@dirstack)));
                  last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
              }
!             print $f ' ' x $#dirstack . "  </Filter>\n";
              pop @dirstack;
          }
  
*************** EOF
*** 388,414 ****
              $left =~ s/^\\//;
              my @pieces = split /\\/, $left;
              push @dirstack, $pieces[0];
!             print F ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
          }
  
!         print F ' ' x $#dirstack . "   <File RelativePath=\"$f\"";
!         if ($f =~ /\.y$/)
          {
!             my $of = $f;
              $of =~ s/\.y$/.c/;
              $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print F '>'
!               . $self->GenerateCustomTool('Running bison on ' . $f,
!                 'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of)
                . '</File>' . "\n";
          }
!         elsif ($f =~ /\.l$/)
          {
!             my $of = $f;
              $of =~ s/\.l$/.c/;
!             print F '>'
!               . $self->GenerateCustomTool('Running flex on ' . $f,
!                 'src\tools\msvc\pgflex.bat ' . $f,$of)
                . '</File>' . "\n";
          }
          elsif (defined($uniquefiles{$file}))
--- 424,450 ----
              $left =~ s/^\\//;
              my @pieces = split /\\/, $left;
              push @dirstack, $pieces[0];
!             print $f ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
          }
  
!         print $f ' ' x $#dirstack . "   <File RelativePath=\"$fileNameWithPath\"";
!         if ($fileNameWithPath =~ /\.y$/)
          {
!             my $of = $fileNameWithPath;
              $of =~ s/\.y$/.c/;
              $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print $f '>'
!               . $self->GenerateCustomTool('Running bison on ' . $fileNameWithPath,
!                 "perl src\\tools\\msvc\\pgbison.pl $fileNameWithPath", $of)
                . '</File>' . "\n";
          }
!         elsif ($fileNameWithPath =~ /\.l$/)
          {
!             my $of = $fileNameWithPath;
              $of =~ s/\.l$/.c/;
!             print $f '>'
!               . $self->GenerateCustomTool('Running flex on ' . $fileNameWithPath,
!                 "perl src\\tools\\msvc\\pgflex.pl $fileNameWithPath", $of)
                . '</File>' . "\n";
          }
          elsif (defined($uniquefiles{$file}))
*************** EOF
*** 417,423 ****
              # File already exists, so fake a new name
              my $obj = $dir;
              $obj =~ s/\\/_/g;
!             print F
  "><FileConfiguration Name=\"Debug|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration></File>\n";
--- 453,459 ----
              # File already exists, so fake a new name
              my $obj = $dir;
              $obj =~ s/\\/_/g;
!             print $f
  "><FileConfiguration Name=\"Debug|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration></File>\n";
*************** EOF
*** 425,464 ****
          else
          {
              $uniquefiles{$file} = 1;
!             print F " />\n";
          }
      }
      while ($#dirstack >= 0)
      {
!         print F ' ' x $#dirstack . "  </Filter>\n";
          pop @dirstack;
      }
!     $self->Footer(*F);
!     close(F);
! }
! 
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
  }
  
  sub WriteHeader
--- 461,477 ----
          else
          {
              $uniquefiles{$file} = 1;
!             print $f " />\n";
          }
      }
      while ($#dirstack >= 0)
      {
!         print $f ' ' x $#dirstack . "  </Filter>\n";
          pop @dirstack;
      }
!     print $f <<EOF;
!  </Files>
! EOF
  }
  
  sub WriteHeader
*************** EOF
*** 478,489 ****
      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 $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
--- 491,502 ----
      print $f <<EOF;
   </Configurations>
  EOF
+     $self->WriteReferences($f);
  }
  
! sub GetAdditionalLinkerDependencies
  {
!     my ($self, $cfgname, $seperator) = @_;
      my $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
*************** sub WriteConfiguration
*** 497,506 ****
                  last;
              }
          }
!         $libs .= $xlib . " ";
      }
!     $libs =~ s/ $//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
  
      my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
  
--- 510,527 ----
                  last;
              }
          }
!         $libs .= $xlib . $seperator;
      }
!     $libs =~ s/.$//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
+     return $libs;
+ }
+ 
+ sub WriteConfiguration
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ' ');
  
      my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
  
*************** sub Footer
*** 563,569 ****
      my ($self, $f) = @_;
  
      print $f <<EOF;
-  </Files>
   <Globals/>
  </VisualStudioProject>
  EOF
--- 584,589 ----
diff -Napcdr -x .git postgresql/src/tools/msvc/Solution.pm postgresql_dev/src/tools/msvc/Solution.pm
*** postgresql/src/tools/msvc/Solution.pm	Wed Jul  6 23:51:59 2011
--- postgresql_dev/src/tools/msvc/Solution.pm	Wed Jul  6 23:39:50 2011
*************** package Solution;
*** 8,17 ****
  use Carp;
  use strict;
  use warnings;
  
! sub new
  {
!     my $junk = shift;
      my $options = shift;
      my $self = {
          projects => {},
--- 8,18 ----
  use Carp;
  use strict;
  use warnings;
+ use VSObjectFactory;
  
! sub _new
  {
!     my $classname = shift;
      my $options = shift;
      my $self = {
          projects => {},
*************** sub new
*** 21,27 ****
          vcver    => undef,
          platform => undef,
      };
!     bless $self;
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
--- 22,28 ----
          vcver    => undef,
          platform => undef,
      };
!     bless($self, $classname);
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
*************** sub new
*** 53,80 ****
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DetermineToolVersions();
  
      return $self;
  }
  
! sub DetermineToolVersions
  {
      my $self = shift;
  
-     # Determine version of vcbuild command, to set proper verison of visual studio
-     open(P,"vcbuild /? |") || die "vcbuild command not found";
-     my $line = <P>;
-     close(P);
-     if ($line !~ /^Microsoft\s*\(R\) Visual C\+\+ [^-]+ - \D+(\d+)\.00\.\d+/)
-     {
-         die "Unable to determine vcbuild version from first line of output!";
-     }
-     if ($1 == 8) { $self->{vcver} = '8.00' }
-     elsif ($1 == 9) { $self->{vcver} = '9.00' }
-     else { die "Unsupported version of Visual Studio: $1" }
-     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';
--- 54,68 ----
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DeterminePlatform();
  
      return $self;
  }
  
! sub DeterminePlatform
  {
      my $self = shift;
  
      # Determine if we are in 32 or 64-bit mode. Do this by seeing if CL has
      # 64-bit only parameters.
      $self->{platform} = 'Win32';
*************** sub AddProject
*** 428,434 ****
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = new Project($name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
--- 416,422 ----
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = VSObjectFactory::CreateProject($self->{vcver}, $name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
*************** sub Save
*** 488,495 ****
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version 9.00
! # Visual Studio 2005
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
--- 476,483 ----
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version $self->{solutionFileVersion}
! # $self->{visualStudioName}
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
*************** EOF
*** 497,503 ****
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}.vcproj", "$proj->{guid}"
  EndProject
  EOF
          }
--- 485,491 ----
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}$proj->{filenameExtension}", "$proj->{guid}"
  EndProject
  EOF
          }
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2005Project.pm postgresql_dev/src/tools/msvc/VC2005Project.pm
*** postgresql/src/tools/msvc/VC2005Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2005Project.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,25 ----
+ package VC2005Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2005 project file
+ #
+ # src/tools/msvc/VC2005Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '8.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2008Project.pm postgresql_dev/src/tools/msvc/VC2008Project.pm
*** postgresql/src/tools/msvc/VC2008Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2008Project.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,25 ----
+ package VC2008Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2008 project file
+ #
+ # src/tools/msvc/VC2008Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '9.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2010Project.pm postgresql_dev/src/tools/msvc/VC2010Project.pm
*** postgresql/src/tools/msvc/VC2010Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2010Project.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,368 ----
+ package VC2010Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2010 project file
+ #
+ # src/tools/msvc/VC2010Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '10.00';
+     $self->{filenameExtension} = '.vcxproj';
+ 
+     return $self;
+ }
+ 
+ sub AddDefine
+ {
+     my ($self, $def) = @_;
+ 
+     $self->{defines} .= $def . ';';
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+ 
+     my @references = @{$self->{references}};
+ 
+     if (scalar(@references))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $ref (@references)
+         {
+             print $f <<EOF;
+     <ProjectReference Include="$ref->{name}$ref->{filenameExtension}">
+       <Project>$ref->{guid}</Project>
+     </ProjectReference>
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+   <ItemGroup>
+ EOF
+     my @grammarFiles = ();
+     my @resourceFiles = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $fileName = $2;
+         if ($fileNameWithPath =~ /\.y$/ or $fileNameWithPath =~ /\.l$/)
+         {
+             push @grammarFiles, $fileNameWithPath;
+         }
+         elsif ($fileNameWithPath =~ /\.rc$/)
+         {
+             push @resourceFiles, $fileNameWithPath;
+         }
+         elsif (defined($uniquefiles{$fileName}))
+         {
+ 
+             # File already exists, so fake a new name
+             my $obj = $dir;
+             $obj =~ s/\\/_/g;
+ 
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath">
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">.\\debug\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">.\\release\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+     </ClCompile>
+ EOF
+         }
+         else
+         {
+             $uniquefiles{$fileName} = 1;
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath" />
+ EOF
+         }
+ 
+     }
+     print $f <<EOF;
+   </ItemGroup>
+ EOF
+     if (scalar(@grammarFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $grammarFile (@grammarFiles)
+         {
+             (my $outputFile = $grammarFile) =~ s/\.(y|l)$/.c/;
+             if ($grammarFile =~ /\.y$/)
+             {
+                 $outputFile =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+             else #if ($grammarFile =~ /\.l$/)
+             {
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+     if (scalar(@resourceFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $rcFile (@resourceFiles)
+         {
+             print $f <<EOF;
+     <ResourceCompile Include="$rcFile" />
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+   <ItemGroup Label="ProjectConfigurations">
+ EOF
+     $self->WriteConfigurationHeader($f, 'Debug');
+     $self->WriteConfigurationHeader($f, 'Release');
+     print $f <<EOF;
+   </ItemGroup>
+   <PropertyGroup Label="Globals">
+     <ProjectGuid>$self->{guid}</ProjectGuid>
+   </PropertyGroup>
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
+ EOF
+     $self->WriteConfigurationPropertyGroup($f, 'Release',{ wholeopt=>'false' });
+     $self->WriteConfigurationPropertyGroup($f, 'Debug',{ wholeopt=>'false' });
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.props" />
+   <ImportGroup Label="ExtensionSettings">
+   </ImportGroup>
+ EOF
+     $self->WritePropertySheetsPropertyGroup($f, 'Release');
+     $self->WritePropertySheetsPropertyGroup($f, 'Debug');
+     print $f <<EOF;
+   <PropertyGroup Label="UserMacros" />
+   <PropertyGroup>
+     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ EOF
+     $self->WriteAdditionalProperties($f, 'Debug');
+     $self->WriteAdditionalProperties($f, 'Release');
+     print $f <<EOF;
+   </PropertyGroup>
+ EOF
+     $self->WriteItemDefinitionGroup(
+         $f, 'Debug',
+         {
+             defs=>'_DEBUG;DEBUG=1;',
+             opt=>'Disabled',
+             strpool=>'false',
+             runtime=>'MultiThreadedDebugDLL'
+         }
+     );
+     $self->WriteItemDefinitionGroup($f, 'Release',
+         { defs=>'', opt=>'Full', strpool=>'true', runtime=>'MultiThreadedDLL' });
+ }
+ 
+ sub WriteConfigurationHeader
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <ProjectConfiguration Include="$cfgname|$self->{platform}">
+       <Configuration>$cfgname</Configuration>
+       <Platform>$self->{platform}</Platform>
+     </ProjectConfiguration>
+ EOF
+ }
+ 
+ sub WriteConfigurationPropertyGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+ 
+     print $f <<EOF;
+   <PropertyGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="Configuration">
+     <ConfigurationType>$cfgtype</ConfigurationType>
+     <UseOfMfc>false</UseOfMfc>
+     <CharacterSet>MultiByte</CharacterSet>
+     <WholeProgramOptimization>$p->{wholeopt}</WholeProgramOptimization>
+   </PropertyGroup>
+ EOF
+ }
+ 
+ sub WritePropertySheetsPropertyGroup
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+   <ImportGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="PropertySheets">
+     <Import Project="\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props" Condition="exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')" Label="LocalAppDataPlatform" />
+   </ImportGroup>
+ EOF
+ }
+ 
+ sub WriteAdditionalProperties
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <OutDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</OutDir>
+     <IntDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</IntDir>
+     <LinkIncremental Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">false</LinkIncremental>
+ EOF
+ }
+ 
+ sub WriteItemDefinitionGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+ 
+     my $includes = $self->{includes};
+     unless ($includes eq '' or $includes =~ /;$/)
+     {
+         $includes .= ';';
+     }
+     print $f <<EOF;
+   <ItemDefinitionGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">
+     <ClCompile>
+       <Optimization>$p->{opt}</Optimization>
+       <AdditionalIncludeDirectories>$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$includes\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+       <PreprocessorDefinitions>WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}\%(PreprocessorDefinitions)</PreprocessorDefinitions>
+       <StringPooling>$p->{strpool}</StringPooling>
+       <RuntimeLibrary>$p->{runtime}</RuntimeLibrary>
+       <DisableSpecificWarnings>$self->{disablewarnings};\%(DisableSpecificWarnings)</DisableSpecificWarnings>
+       <AdditionalOptions>/MP \%(AdditionalOptions)</AdditionalOptions>
+       <AssemblerOutput>
+       </AssemblerOutput>
+       <AssemblerListingLocation>.\\$cfgname\\$self->{name}\\</AssemblerListingLocation>
+       <ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
+       <ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
+       <BrowseInformation>false</BrowseInformation>
+       <WarningLevel>Level3</WarningLevel>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+       <CompileAs>Default</CompileAs>
+     </ClCompile>
+     <Link>
+       <OutputFile>.\\$cfgname\\$self->{name}\\$self->{name}.$self->{type}</OutputFile>
+       <AdditionalDependencies>$libs;\%(AdditionalDependencies)</AdditionalDependencies>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <AdditionalLibraryDirectories>\%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+       <IgnoreSpecificDefaultLibraries>libc;\%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+       <StackReserveSize>4194304</StackReserveSize>
+       <GenerateDebugInformation>true</GenerateDebugInformation>
+       <ProgramDatabaseFile>.\\$cfgname\\$self->{name}\\$self->{name}.pdb</ProgramDatabaseFile>
+       <GenerateMapFile>false</GenerateMapFile>
+       <MapFileName>.\\$cfgname\\$self->{name}\\$self->{name}.map</MapFileName>
+       <SubSystem>Console</SubSystem>
+       <TargetMachine>$targetmachine</TargetMachine>
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f
+ "      <AdditionalOptions>/ignore:$self->{disablelinkerwarnings} \%(AdditionalOptions)</AdditionalOptions>\n";
+     }
+     if ($self->{implib})
+     {
+         my $l = $self->{implib};
+         $l =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ImportLibrary>$l</ImportLibrary>\n";
+     }
+     if ($self->{def})
+     {
+         my $d = $self->{def};
+         $d =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ModuleDefinitionFile>$d</ModuleDefinitionFile>\n";
+     }
+     print $f <<EOF;
+     </Link>
+     <ResourceCompile>
+       <AdditionalIncludeDirectories>src\\include;\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+     </ResourceCompile>
+ EOF
+     if ($self->{builddef})
+     {
+         print $f <<EOF;
+     <PreLinkEvent>
+       <Message>Generate DEF file</Message>
+       <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+     </PreLinkEvent>
+ EOF
+     }
+     print $f <<EOF;
+   </ItemDefinitionGroup>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+     $self->WriteReferences($f);
+ 
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.targets" />
+   <ImportGroup Label="ExtensionTargets">
+   </ImportGroup>
+ </Project>
+ EOF
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2005Solution.pm postgresql_dev/src/tools/msvc/VS2005Solution.pm
*** postgresql/src/tools/msvc/VS2005Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2005Solution.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2005Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2005 solution file
+ #
+ # src/tools/msvc/VS2005Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '9.00';
+     $self->{vcver} = '8.00';
+     $self->{visualStudioName} = 'Visual Studio 2005';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2008Solution.pm postgresql_dev/src/tools/msvc/VS2008Solution.pm
*** postgresql/src/tools/msvc/VS2008Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2008Solution.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2008Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2008 solution file
+ #
+ # src/tools/msvc/VS2008Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '10.00';
+     $self->{vcver} = '9.00';
+     $self->{visualStudioName} = 'Visual Studio 2008';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2010Solution.pm postgresql_dev/src/tools/msvc/VS2010Solution.pm
*** postgresql/src/tools/msvc/VS2010Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2010Solution.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2010Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2010 solution file
+ #
+ # src/tools/msvc/VS2010Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '11.00';
+     $self->{vcver} = '10.00';
+     $self->{visualStudioName} = 'Visual Studio 2010';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VSObjectFactory.pm postgresql_dev/src/tools/msvc/VSObjectFactory.pm
*** postgresql/src/tools/msvc/VSObjectFactory.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VSObjectFactory.pm	Wed Jul  6 23:39:50 2011
***************
*** 0 ****
--- 1,126 ----
+ package VSObjectFactory;
+ 
+ #
+ # Package that creates Visual Studio wrapper objects for msvc build
+ #
+ # src/tools/msvc/VSObjectFactory.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ 
+ use Exporter;
+ use Project;
+ use Solution;
+ use VC2005Project;
+ use VC2008Project;
+ use VC2010Project;
+ use VS2005Solution;
+ use VS2008Solution;
+ use VS2010Solution;
+ 
+ our (@ISA, @EXPORT_OK);
+ @ISA = qw(Exporter);
+ @EXPORT_OK = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
+ 
+ sub CreateSolution
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VS2005Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VS2008Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VS2010Solution(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub CreateProject
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VC2005Project(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VC2008Project(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VC2010Project(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub DetermineVisualStudioVersion
+ {
+     my $nmakeVersion = shift;
+ 
+     if (!defined($nmakeVersion))
+     {
+ 
+         # Determine version of nmake command, to set proper verison of visual studio
+         # we use nmake as it has existed for a long time and still exists in visual studio 2010
+         open(P,"nmake /? 2>&1 |")
+           || croak "Unable to determine Visual Studio version: The nmake command wasn't found.";
+         while(<P>)
+         {
+             chomp;
+             if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+             {
+                 return _GetVisualStudioVersion($1, $2);
+             }
+         }
+         close(P);
+     }
+     elsif($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+     {
+         return _GetVisualStudioVersion($1, $2);
+     }
+     croak "Unable to determine Visual Studio version: The nmake version could not be determined.";
+ }
+ 
+ sub _GetVisualStudioVersion
+ {
+     my($major, $minor) = @_;
+     if ($major > 10)
+     {
+         carp
+ "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
+         return '10.00';
+     }
+     elsif ($major < 6)
+     {
+         croak
+ "Unable to determine Visual Studio version: Visual Studio versions before 6.0 aren't supported.";
+     }
+     return "$major.$minor";
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/build.pl postgresql_dev/src/tools/msvc/build.pl
*** postgresql/src/tools/msvc/build.pl	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/build.pl	Wed Jul  6 23:39:50 2011
*************** our $config;
*** 33,39 ****
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
--- 33,39 ----
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! my $vcver = Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
*************** elsif ($ARGV[0] ne "RELEASE")
*** 50,56 ****
  
  # ... and do it
  
! if ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
--- 50,60 ----
  
  # ... and do it
  
! if ($buildwhat and $vcver eq '10.00')
! {
!     system("msbuild $buildwhat.vcxproj /verbosity:detailed /p:Configuration=$bconf");
! }
! elsif ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
diff -Napcdr -x .git postgresql/src/tools/msvc/builddoc.pl postgresql_dev/src/tools/msvc/builddoc.pl
*** postgresql/src/tools/msvc/builddoc.pl	Wed Jul  6 23:51:59 2011
--- postgresql_dev/src/tools/msvc/builddoc.pl	Wed Jul  6 23:39:50 2011
*************** $cmd =
*** 69,76 ****
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
!   ."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
--- 69,76 ----
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd =
!   "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
diff -Napcdr -x .git postgresql/src/tools/msvc/clean.bat postgresql_dev/src/tools/msvc/clean.bat
*** postgresql/src/tools/msvc/clean.bat	Tue Jul  5 05:55:29 2011
--- postgresql_dev/src/tools/msvc/clean.bat	Wed Jul  6 23:39:50 2011
*************** if exist ..\msvc if exist ..\..\..\src c
*** 10,17 ****
--- 10,21 ----
  if exist debug rd /s /q debug
  if exist release rd /s /q release
  for %%f in (*.vcproj) do del %%f
+ for %%f in (*.vcxproj) do del %%f
+ for %%f in (*.vcxproj.user) do del %%f
  if exist pgsql.sln del /q pgsql.sln
  if exist pgsql.sln.cache del /q pgsql.sln.cache
+ if exist pgsql.sdf del /q pgsql.sdf
+ if exist pgsql.suo del /q /a:H pgsql.suo
  del /s /q src\bin\win32ver.rc 2> NUL
  del /s /q src\interfaces\win32ver.rc 2> NUL
  if exist src\backend\win32ver.rc del /q src\backend\win32ver.rc
#7Craig Ringer
craig@postnewspapers.com.au
In reply to: Brar Piening (#6)
Re: Review of VS 2010 support patches

On 7/07/2011 8:26 AM, Brar Piening wrote:

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

OK, I've gone through builds with way too many versions of the Windows
SDK and have test results to report.

The short version: please commit so I never, ever, ever have to do this
again ;-) . I don't see anything newly broken; the only issues I hit
were in master as well, and are probably related to local configuration
issues and/or the sheer profusion of Windows SDK releases I've burdened
my poor laptop with.

Note that x64 builds reported below are configured for plperl and
plpython only. Other config.pl options are left at 'undef'.

Test results:
=============

VS 2005
-------

- SDK 6.0 (VS 2005) x86: OK, vcregress check passed

- SDK 6.0 (VS 2005) x64: OK, vcregress check passed

VS 2008
-------

- SDK 6.1 (VS 2008) x86: OK, vcregress check passed

- SDK 6.1 (VS 2008) x64: Failed - vcbuild exited with code 255.
(Also fails on unpatched git master x64)
Since I'm getting crash report dialogs from
vcbuild, I'm not inclined to blame Pg for this
issue.

- SDK 6.1 (VS 2008) x64 (only plperl enabled): OK, vcregress passed

VS 2010
-------

- SDK 7.0A (VS 2010) x86: OK, vcregress passed
- SDK 7.0A (VS 2010) x64: [Pending, missing x64 tools]

Latest Windows SDK
------------------

- SDK 7.1 x86: OK, vcregress passed
- SDK 7.1 x64: OK (incl. plpython), vcregress passed

Won't test:
===========

- itanium. Does Pg build for itanium as things stand, anyway? Would
anybody notice or care if it didn't?

Not tested yet, unsure if I'll have time
========================================

- vcregress plcheck, vcregress contrib for each combo

- x64 builds with anything more than plperl and plpython enabled.
Library availability is a bit of an issue, and building all those
libraries for x64 is outside what I can currently commit to, especially
as they all require different build methods and some appear to require
patches/fixes to build at all.

- ossp-uuid . No binaries available, doesn't have an NMakefile or
vs project, and

Frankly, I suggest leaving these tests for the buildfarm to sort out. I
don't see any sign of build process issues; they all build fine, and
it's pretty darn unlikely that build changes would cause them to break
at runtime. Windows buildfarm coverage looks pretty decent these days.

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088 Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

#8Brar Piening
brar@gmx.de
In reply to: Craig Ringer (#7)
1 attachment(s)
Re: Review of VS 2010 support patches

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Craig Ringer <craig@postnewspapers.com.au>
To: Brar Piening <brar@gmx.de>
Date: 07.07.2011 16:44

Frankly, I suggest leaving these tests for the buildfarm to sort out.
I don't see any sign of build process issues; they all build fine, and
it's pretty darn unlikely that build changes would cause them to break
at runtime. Windows buildfarm coverage looks pretty decent these days.

As I had no Idea whether the buildfarm is even ready to work with VS
2010 I set out and tested it.

I can happily tell you that I have just now completed my first
successful buildfarm run using the attached build-farm.conf

Regards,

Brar

Attachments:

build-farm.conftext/plain; name=build-farm.confDownload
#9Magnus Hagander
magnus@hagander.net
In reply to: Brar Piening (#6)
1 attachment(s)
Re: Review of VS 2010 support patches

On Thu, Jul 7, 2011 at 02:26, Brar Piening <brar@gmx.de> wrote:

-------- Original Message  --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan <andrew@dunslane.net>
To: Brar Piening <brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files get
commited.

I'm just doing some final testing and preparing to commit the new pgflex
and pgbison.

The attached patch includes documentation changes and excludes my versions
of pgbison.pl and pgflex.pl which have been replaced by Andrews' versions
that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

Something is strange here. Did you run perltidy with the exact
parameters documented in the README file? If so, perltidy seems to be
version- or platform- dependent. I ran it, and got a slightly
different patch. It's not big differences, but the simple fact that
perltidy doesn't always generate the same result is annoying.

Can you run it again, and make sure you get the exact same diff? So
that it wasn't accidentally run off the wrong version or something?

I've attached the differences between your perltidy and my perltidy run.

I'm using (perltidy -v): "This is perltidy, v20090616"

(My plan was to just commit a perltidy run to keep that part out of
the patch for easier handling, but I'd like to figure out this
difference first..)

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

Attachments:

post_perltidy.patchtext/x-patch; charset=US-ASCII; name=post_perltidy.patchDownload
diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm
index a7720a0..1fccfe8 100644
--- a/src/tools/msvc/Install.pm
+++ b/src/tools/msvc/Install.pm
@@ -56,11 +56,8 @@ sub Install
     my $majorver = DetermineMajorVersion();
     print "Installing version $majorver for $conf in $target\n";
 
-    EnsureDirectories(
-        $target, 'bin', 'lib', 'share',
-        'share/timezonesets','share/extension', 'share/contrib','doc',
-        'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
-    );
+    EnsureDirectories($target, 'bin', 'lib', 'share','share/timezonesets','share/extension',
+        'share/contrib','doc','doc/extension', 'doc/contrib','symbols', 'share/tsearch_data');
 
     CopySolutionOutput($conf, $target);
     lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
@@ -470,8 +467,7 @@ sub CopyIncludeFiles
         $target . '/include/server/',
         'src/include/', 'pg_config.h', 'pg_config_os.h'
     );
-    CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
-        'gram.h');
+    CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/','gram.h');
     CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
     my $D;
     opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
diff --git a/src/tools/msvc/builddoc.pl b/src/tools/msvc/builddoc.pl
index 6531e98..8d8d8a3 100644
--- a/src/tools/msvc/builddoc.pl
+++ b/src/tools/msvc/builddoc.pl
@@ -69,8 +69,8 @@ $cmd =
   ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
 system($cmd); # die "openjade" if $?;
 print "Running collateindex...\n";
-$cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
-  ."-o bookindex.sgml HTML.index";
+$cmd =
+  "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "."-o bookindex.sgml HTML.index";
 system($cmd);
 die "collateindex" if $?;
 mkdir "html";
#10Brar Piening
brar@gmx.de
In reply to: Magnus Hagander (#9)
Re: Review of VS 2010 support patches

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Magnus Hagander <magnus@hagander.net>
To: Brar Piening <brar@gmx.de>
Date: 08.07.2011 11:38

Sorry for the late response - I've been on a wedding this weekend.

Something is strange here. Did you run perltidy with the exact
parameters documented in the README file?

Yes - I usually even copy paste it from the README as "perltidy -b -bl
-nsfs -naws -l=100 -ole=unix *.pl *.pm" (pasted once more) is hard to
remember and takes a while to type.

If so, perltidy seems to be
version- or platform- dependent. I ran it, and got a slightly
different patch. It's not big differences, but the simple fact that
perltidy doesn't always generate the same result is annoying.

Can you run it again, and make sure you get the exact same diff? So
that it wasn't accidentally run off the wrong version or something?

I just rechecked that applying my two patches vs. applying my two
patches + running the above perltidy command gives no difference (0 byte
patch).

I've attached the differences between your perltidy and my perltidy run.

I'm using (perltidy -v): "This is perltidy, v20090616"

I'm currently using (perl -v): "This is perl 5, version 14, subversion 1
(v5.14.1) built for MSWin32-x64-multi-thread"
and
(perltidy -v): "This is perltidy, v20101217"

But I've just recently upgraded to the latest Perl version.
The patch has been produced using some 5.12.? ActivePerl and it's
corresponding perltidy version which (whatever it was) obviously
produced the same result for me.

http://perltidy.sourceforge.net/ChangeLog.html#2010_12_17 doesn't seem
to have any Information which would explain our different patches.

Strange...

Regards,

Brar

#11Magnus Hagander
magnus@hagander.net
In reply to: Brar Piening (#10)
Re: Review of VS 2010 support patches

On Sun, Jul 10, 2011 at 20:46, Brar Piening <brar@gmx.de> wrote:

Sorry for the late response - I've been on a wedding this weekend.

Something is strange here. Did you run perltidy with the exact
parameters documented in the README file?

Yes - I usually even copy paste it from the README as "perltidy -b -bl -nsfs
-naws -l=100 -ole=unix *.pl *.pm" (pasted once more) is hard to remember and
takes a while to type.

Bleh, that's annoying - that means it behaves different in different versions :S

If so, perltidy seems to be
version- or platform- dependent. I ran it, and got a slightly
different patch. It's not big differences, but the simple fact that
perltidy doesn't always generate the same result is annoying.

Can you run it again, and make sure you get the exact same diff? So
that it wasn't accidentally run off the wrong version or something?

I just rechecked that applying my two patches vs. applying my two patches +
running the above perltidy command gives no difference (0 byte patch).

I've attached the differences between your perltidy and my perltidy run.

I'm using (perltidy -v): "This is perltidy, v20090616"

I'm currently using (perl -v): "This is perl 5, version 14, subversion 1
(v5.14.1) built for MSWin32-x64-multi-thread"
and
(perltidy -v): "This is perltidy, v20101217"

But I've just recently upgraded to the latest Perl version.
The patch has been produced using some 5.12.? ActivePerl and it's
corresponding perltidy version which (whatever it was) obviously produced
the same result for me.

I'm using 5.10... Not sure if it's the perl version or more likely the
perltidy version that causes the difference, but there's not too much
we can do about that. I'm not sure the differences are big enough that
we actually want to care about it - I think it's easier to just take
changes caused by it out of each commit. We're still getting the large
majority as the same.

So - for now, I have made a perltidy run and committed it, which
should make it slightly easier for reviewing the actual patch :-)

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#12Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#6)
Re: Review of VS 2010 support patches

On 07/06/2011 08:26 PM, Brar Piening wrote:

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan <andrew@dunslane.net>
To: Brar Piening <brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files
get commited.

I'm just doing some final testing and preparing to commit the new
pgflex and pgbison.

The attached patch includes documentation changes and excludes my
versions of pgbison.pl and pgflex.pl which have been replaced by
Andrews' versions that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

I just started looking at this a bit. One small question: why are we
using "use base qw(foo);" instead of "use parent qw(foo);" which I
understand is preferred these days?

cheers

andrew

#13Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#12)
Re: Review of VS 2010 support patches

On Sun, Jul 31, 2011 at 03:25, Andrew Dunstan <andrew@dunslane.net> wrote:

On 07/06/2011 08:26 PM, Brar Piening wrote:

-------- Original Message  --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan <andrew@dunslane.net>
To: Brar Piening <brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files get
commited.

I'm just doing some final testing and preparing to commit the new pgflex
and pgbison.

The attached patch includes documentation changes and excludes my versions
of pgbison.pl and pgflex.pl which have been replaced by Andrews' versions
that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

I just started looking at this a bit. One small question: why are we using
"use base qw(foo);" instead of "use parent qw(foo);" which I understand is
preferred these days?

I am no perl expert, but I see we are using this already today - in
code written by you in one case ;) I'd assume it was just following
the same standard... If the other way is the way to do it today, I see
no reason not to change it to use that.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#14Robert Haas
robertmhaas@gmail.com
In reply to: Magnus Hagander (#13)
Re: Review of VS 2010 support patches

On Wed, Aug 10, 2011 at 9:03 AM, Magnus Hagander <magnus@hagander.net> wrote:

I am no perl expert, but I see we are using this already today - in
code written by you in one case ;) I'd assume it was just following
the same standard... If the other way is the way to do it today, I see
no reason not to change it to use that.

This is the first I'm hearing of use parent - has that been around
long enough that we needn't worry about breaking old Perl versions?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#15Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#13)
Re: Review of VS 2010 support patches

On 08/10/2011 09:03 AM, Magnus Hagander wrote:

On Sun, Jul 31, 2011 at 03:25, Andrew Dunstan<andrew@dunslane.net> wrote:

On 07/06/2011 08:26 PM, Brar Piening wrote:

-------- Original Message --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan<andrew@dunslane.net>
To: Brar Piening<brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files get
commited.

I'm just doing some final testing and preparing to commit the new pgflex
and pgbison.

The attached patch includes documentation changes and excludes my versions
of pgbison.pl and pgflex.pl which have been replaced by Andrews' versions
that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

I just started looking at this a bit. One small question: why are we using
"use base qw(foo);" instead of "use parent qw(foo);" which I understand is
preferred these days?

I am no perl expert, but I see we are using this already today - in
code written by you in one case ;) I'd assume it was just following
the same standard... If the other way is the way to do it today, I see
no reason not to change it to use that.

Umm, where are we using it today?

[andrew@emma pg_head]$ grep -r -P 'use\s+base' .
./doc/src/sgml/release-old.sgml: what lexer you use based on the
platform you use.
./doc/src/sgml/charset.sgml: encoding to use based on the
specified or default locale.
./src/backend/commands/aggregatecmds.c: * Old style: use
basetype parameter. This supports aggregates of
./autom4te.cache/output.0:# Required to use basename.
./autom4te.cache/output.0:# Required to use basename.
./configure:# Required to use basename.
./configure:# Required to use basename.
[andrew@emma pg_head]$

cheers

andrew

#16Andrew Dunstan
andrew@dunslane.net
In reply to: Robert Haas (#14)
Re: Review of VS 2010 support patches

On 08/10/2011 09:21 AM, Robert Haas wrote:

On Wed, Aug 10, 2011 at 9:03 AM, Magnus Hagander<magnus@hagander.net> wrote:

I am no perl expert, but I see we are using this already today - in
code written by you in one case ;) I'd assume it was just following
the same standard... If the other way is the way to do it today, I see
no reason not to change it to use that.

This is the first I'm hearing of use parent - has that been around
long enough that we needn't worry about breaking old Perl versions?

Good question. Maybe not.

cheers

andrew

#17Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#15)
Re: Review of VS 2010 support patches

On Wed, Aug 10, 2011 at 15:25, Andrew Dunstan <andrew@dunslane.net> wrote:

On 08/10/2011 09:03 AM, Magnus Hagander wrote:

On Sun, Jul 31, 2011 at 03:25, Andrew Dunstan<andrew@dunslane.net>  wrote:

On 07/06/2011 08:26 PM, Brar Piening wrote:

-------- Original Message  --------
Subject: Re: [HACKERS] Review of VS 2010 support patches
From: Andrew Dunstan<andrew@dunslane.net>
To: Brar Piening<brar@gmx.de>
Date: 06.07.2011 22:58

I'll remove my versions from the patch (v9 probably) if those files
get
commited.

I'm just doing some final testing and preparing to commit the new
pgflex
and pgbison.

The attached patch includes documentation changes and excludes my
versions
of pgbison.pl and pgflex.pl which have been replaced by Andrews'
versions
that are already commited.

As before "perltidy_before.patch" has to be applied first and
"VS2010v9.patch" second.

I just started looking at this a bit. One small question: why are we
using
"use base qw(foo);" instead of "use parent qw(foo);" which I understand
is
preferred these days?

I am no perl expert, but I see we are using this already today - in
code written by you in one case ;) I'd assume it was just following
the same standard... If the other way is the way to do it today, I see
no reason not to change it to use that.

Umm, where are we using it today?

  [andrew@emma pg_head]$ grep -r -P 'use\s+base' .
  ./doc/src/sgml/release-old.sgml:   what lexer you use based on the
  platform you use.
  ./doc/src/sgml/charset.sgml:     encoding to use based on the
  specified or default locale.
  ./src/backend/commands/aggregatecmds.c:         * Old style: use
  basetype parameter.  This supports aggregates of
  ./autom4te.cache/output.0:# Required to use basename.
  ./autom4te.cache/output.0:# Required to use basename.
  ./configure:# Required to use basename.
  ./configure:# Required to use basename.
  [andrew@emma pg_head]$

Meh. I am clearly not back in the game since my vacation. I didn't
realize base was a keyword... Ignore and move on, nothing to see here.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#18Brar Piening
brar@gmx.de
In reply to: Brar Piening (#6)
1 attachment(s)
Re: Review of VS 2010 support patches

Brar Piening wrote:

The attached patch includes documentation changes and excludes my
versions of pgbison.pl and pgflex.pl which have been replaced by
Andrews' versions that are already commited.

Building current head today I noticed that the patch doesn't apply
cleanly anymore.

Attached is a new version.

Regards,

Brar

Attachments:

VS2010v10.patchtext/plain; name=VS2010v10.patchDownload
diff -Napcdr -x .git postgresql/doc/src/sgml/install-windows.sgml postgresql_dev/doc/src/sgml/install-windows.sgml
*** postgresql/doc/src/sgml/install-windows.sgml	Wed Sep 28 19:23:58 2011
--- postgresql_dev/doc/src/sgml/install-windows.sgml	Wed Sep 28 19:32:22 2011
***************
*** 20,29 ****
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Platform SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005 or 2008</productname>. In some cases
!   that requires the installation of the <productname>Platform SDK</productname>
    in addition to the compiler.
   </para>
  
--- 20,29 ----
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Windows SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005, 2008 or 2010</productname>. In some cases
!   that requires the installation of the <productname>Windows SDK</productname>
    in addition to the compiler.
   </para>
  
***************
*** 69,100 ****
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Platform SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Platform SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way us to use the compilers in the <productname>Platform SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL supports the compilers from
!   <productname>Visual Studio 2005</productname> and
!   <productname>Visual Studio 2008</productname>. When using the Platform SDK
!   only, or when building for 64-bit Windows, only
!   <productname>Visual Studio 2008</productname> is supported.
!   <productname>Visual Studio 2010</productname> is not yet supported.
!  </para>
! 
!  <para>
!   When building using the <productname>Platform SDK</productname>, versions
!   6.0 to 7.0 of the SDK are supported. Older or newer versions will not work.
!   In particular, versions from 7.0a and later will not work, since
!   they include compilers from <productname>Visual Studio 2010</productname>.
   </para>
  
   <para>
--- 69,94 ----
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Microsoft Windows SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Microsoft Windows SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way is to use the compilers in the <productname>Windows SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL is known to support compilation using the compilers shipped with
!   <productname>Visual Studio 2005</productname> to
!   <productname>Visual Studio 2010</productname> (including Express editions),
!   as well as standalone Windows SDK releases 6.0 to 7.1.
!   64-bit PostgreSQL builds are only supported with
!   <productname>Microsoft Windows SDK</productname> version 6.0a and above or
!   <productname>Visual Studio 2008</productname> and above.
   </para>
  
   <para>
***************
*** 104,114 ****
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>. In the
!   <productname>Platform SDK</productname>, start the
!   <application>CMD shell</application> listed under the SDK on the Start Menu.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
--- 98,110 ----
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
+   In the <productname>Microsoft Windows SDK</productname>, start the
+   <application>CMD shell</application> listed under the SDK on the Start Menu.
+   In recent SDK versions you can change the targeted CPU architecture by using
+   the <command>setenv</command> command.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 148,164 ****
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Platform SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Platform SDK</productname> (currently
!       version 7.0), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Platform SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
--- 144,160 ----
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Windows SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Windows SDK</productname> (currently
!       version 7.1), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Windows SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 202,207 ****
--- 198,207 ----
        Bison can be downloaded from <ulink url="http://gnuwin32.sourceforge.net"></>.
        Flex can be downloaded from
        <ulink url="http://www.postgresql.org/ftp/misc/winflex/"></>.
+       If you are using <productname>msysGit</productname> for accessing the
+       PostgreSQL <productname>Git</productname> repository you probably already
+       have recent versions of bison and flex in your <productname>Git</productname>
+       binary directory.
       </para>
  
       <note>
*************** $ENV{DOCROOT}='c:\docbook';
*** 479,485 ****
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Platform SDK</productname> method is recommended.
   </para>
  
   <para>
--- 479,485 ----
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Windows SDK</productname> method is recommended.
   </para>
  
   <para>
diff -Napcdr -x .git postgresql/src/tools/msvc/Install.pm postgresql_dev/src/tools/msvc/Install.pm
*** postgresql/src/tools/msvc/Install.pm	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/Install.pm	Wed Sep 28 19:26:02 2011
*************** sub Install
*** 56,66 ****
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories(
!         $target, 'bin', 'lib', 'share',
!         'share/timezonesets','share/extension', 'share/contrib','doc',
!         'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
!     );
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
--- 56,63 ----
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories($target, 'bin', 'lib', 'share','share/timezonesets','share/extension',
!         'share/contrib','doc','doc/extension', 'doc/contrib','symbols', 'share/tsearch_data');
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
*************** sub CopySolutionOutput
*** 186,191 ****
--- 183,195 ----
      my $rem = qr{Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"\) = "([^"]+)"};
  
      my $sln = read_file("pgsql.sln") || croak "Could not open pgsql.sln\n";
+ 
+     my $vcproj = 'vcproj';
+     if ($sln =~ /Microsoft Visual Studio Solution File, Format Version (\d+)\.\d+/ && $1 >= 11)
+     {
+         $vcproj = 'vcxproj';
+     }
+ 
      print "Copying build output files...";
      while ($sln =~ $rem)
      {
*************** sub CopySolutionOutput
*** 195,220 ****
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.vcproj") || croak "Could not open $pf.vcproj\n";
!         if ($proj !~ qr{ConfigurationType="([^"]+)"})
!         {
!             croak "Could not parse $pf.vcproj\n";
!         }
!         if ($1 == 1)
          {
!             $dir = "bin";
!             $ext = "exe";
          }
!         elsif ($1 == 2)
          {
!             $dir = "lib";
!             $ext = "dll";
          }
          else
          {
! 
!             # Static lib, such as libpgport, only used internally during build, don't install
!             next;
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
--- 199,246 ----
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.$vcproj") || croak "Could not open $pf.$vcproj\n";
!         if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
          {
!             if ($1 == 1)
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 == 2)
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
!         elsif ($vcproj eq 'vcxproj' && $proj =~ qr{<ConfigurationType>(\w+)</ConfigurationType>})
          {
!             if ($1 eq 'Application')
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 eq 'DynamicLibrary')
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else # 'StaticLibrary'
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
          else
          {
!             croak "Could not parse $pf.$vcproj\n";
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
*************** sub CopyIncludeFiles
*** 470,477 ****
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
!         'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
--- 496,502 ----
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/','gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
diff -Napcdr -x .git postgresql/src/tools/msvc/Mkvcbuild.pm postgresql_dev/src/tools/msvc/Mkvcbuild.pm
*** postgresql/src/tools/msvc/Mkvcbuild.pm	Wed Sep 28 19:23:58 2011
--- postgresql_dev/src/tools/msvc/Mkvcbuild.pm	Wed Sep 28 19:26:02 2011
*************** sub mkvcbuild
*** 45,51 ****
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     $solution = new Solution($config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
--- 45,53 ----
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     my $vsVersion = VSObjectFactory::DetermineVisualStudioVersion();
! 
!     $solution = VSObjectFactory::CreateSolution($vsVersion, $config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
*************** sub mkvcbuild
*** 490,495 ****
--- 492,498 ----
      $pgregress->AddReference($libpgport);
  
      $solution->Save();
+     return $solution->{vcver};
  }
  
  #####################
diff -Napcdr -x .git postgresql/src/tools/msvc/Project.pm postgresql_dev/src/tools/msvc/Project.pm
*** postgresql/src/tools/msvc/Project.pm	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/Project.pm	Wed Sep 28 19:26:02 2011
*************** use strict;
*** 10,18 ****
  use warnings;
  use File::Basename;
  
! sub new
  {
!     my ($junk, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
--- 10,18 ----
  use warnings;
  use File::Basename;
  
! sub _new
  {
!     my ($classname, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
*************** sub new
*** 20,43 ****
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name            => $name,
!         type            => $type,
!         guid            => Win32::GuidGen(),
!         files           => {},
!         references      => [],
!         libraries       => [],
!         suffixlib       => [],
!         includes        => '',
!         prefixincludes  => '',
!         defines         => ';',
!         solution        => $solution,
!         disablewarnings => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         vcver           => $solution->{vcver},
!         platform        => $solution->{platform},
      };
  
!     bless $self;
      return $self;
  }
  
--- 20,46 ----
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name                  => $name,
!         type                  => $type,
!         guid                  => Win32::GuidGen(),
!         files                 => {},
!         references            => [],
!         libraries             => [],
!         suffixlib             => [],
!         includes              => '',
!         prefixincludes        => '',
!         defines               => ';',
!         solution              => $solution,
!         disablewarnings       => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
! 
!         # vcver has to be set in derived classes
!         vcver                 => undef,
!         filenameExtension     => '.vcproj',
!         platform              => $solution->{platform},
      };
  
!     bless($self, $classname);
      return $self;
  }
  
*************** sub Save
*** 355,371 ****
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}.vcproj") || croak("Could not write to $self->{name}.vcproj\n");
      $self->WriteHeader(*F);
!     $self->WriteReferences(*F);
!     print F <<EOF;
   <Files>
  EOF
      my @dirstack = ();
      my %uniquefiles;
!     foreach my $f (sort keys %{ $self->{files} })
      {
!         confess "Bad format filename '$f'\n" unless ($f =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
          my $dir = $1;
          my $file = $2;
  
--- 358,407 ----
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}$self->{filenameExtension}")
!       || croak("Could not write to $self->{name}$self->{filenameExtension}\n");
      $self->WriteHeader(*F);
!     $self->WriteFiles(*F);
!     $self->Footer(*F);
!     close(F);
! }
! 
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
! }
! 
! sub WriteFiles
! {
!     my ($self, $f) = @_;
!     print $f <<EOF;
   <Files>
  EOF
      my @dirstack = ();
      my %uniquefiles;
!     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
      {
!         confess "Bad format filename '$fileNameWithPath'\n"
!           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
          my $dir = $1;
          my $file = $2;
  
*************** EOF
*** 377,383 ****
                  last if (length($dir) == length(join('\\',@dirstack)));
                  last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
              }
!             print F ' ' x $#dirstack . "  </Filter>\n";
              pop @dirstack;
          }
  
--- 413,419 ----
                  last if (length($dir) == length(join('\\',@dirstack)));
                  last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
              }
!             print $f ' ' x $#dirstack . "  </Filter>\n";
              pop @dirstack;
          }
  
*************** EOF
*** 388,414 ****
              $left =~ s/^\\//;
              my @pieces = split /\\/, $left;
              push @dirstack, $pieces[0];
!             print F ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
          }
  
!         print F ' ' x $#dirstack . "   <File RelativePath=\"$f\"";
!         if ($f =~ /\.y$/)
          {
!             my $of = $f;
              $of =~ s/\.y$/.c/;
              $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print F '>'
!               . $self->GenerateCustomTool('Running bison on ' . $f,
!                 'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of)
                . '</File>' . "\n";
          }
!         elsif ($f =~ /\.l$/)
          {
!             my $of = $f;
              $of =~ s/\.l$/.c/;
!             print F '>'
!               . $self->GenerateCustomTool('Running flex on ' . $f,
!                 'src\tools\msvc\pgflex.bat ' . $f,$of)
                . '</File>' . "\n";
          }
          elsif (defined($uniquefiles{$file}))
--- 424,450 ----
              $left =~ s/^\\//;
              my @pieces = split /\\/, $left;
              push @dirstack, $pieces[0];
!             print $f ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
          }
  
!         print $f ' ' x $#dirstack . "   <File RelativePath=\"$fileNameWithPath\"";
!         if ($fileNameWithPath =~ /\.y$/)
          {
!             my $of = $fileNameWithPath;
              $of =~ s/\.y$/.c/;
              $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print $f '>'
!               . $self->GenerateCustomTool('Running bison on ' . $fileNameWithPath,
!                 "perl src\\tools\\msvc\\pgbison.pl $fileNameWithPath", $of)
                . '</File>' . "\n";
          }
!         elsif ($fileNameWithPath =~ /\.l$/)
          {
!             my $of = $fileNameWithPath;
              $of =~ s/\.l$/.c/;
!             print $f '>'
!               . $self->GenerateCustomTool('Running flex on ' . $fileNameWithPath,
!                 "perl src\\tools\\msvc\\pgflex.pl $fileNameWithPath", $of)
                . '</File>' . "\n";
          }
          elsif (defined($uniquefiles{$file}))
*************** EOF
*** 417,423 ****
              # File already exists, so fake a new name
              my $obj = $dir;
              $obj =~ s/\\/_/g;
!             print F
  "><FileConfiguration Name=\"Debug|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration></File>\n";
--- 453,459 ----
              # File already exists, so fake a new name
              my $obj = $dir;
              $obj =~ s/\\/_/g;
!             print $f
  "><FileConfiguration Name=\"Debug|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
                . "_$file.obj\" /></FileConfiguration></File>\n";
*************** EOF
*** 425,464 ****
          else
          {
              $uniquefiles{$file} = 1;
!             print F " />\n";
          }
      }
      while ($#dirstack >= 0)
      {
!         print F ' ' x $#dirstack . "  </Filter>\n";
          pop @dirstack;
      }
!     $self->Footer(*F);
!     close(F);
! }
! 
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
  }
  
  sub WriteHeader
--- 461,477 ----
          else
          {
              $uniquefiles{$file} = 1;
!             print $f " />\n";
          }
      }
      while ($#dirstack >= 0)
      {
!         print $f ' ' x $#dirstack . "  </Filter>\n";
          pop @dirstack;
      }
!     print $f <<EOF;
!  </Files>
! EOF
  }
  
  sub WriteHeader
*************** EOF
*** 478,489 ****
      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 $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
--- 491,502 ----
      print $f <<EOF;
   </Configurations>
  EOF
+     $self->WriteReferences($f);
  }
  
! sub GetAdditionalLinkerDependencies
  {
!     my ($self, $cfgname, $seperator) = @_;
      my $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
*************** sub WriteConfiguration
*** 497,506 ****
                  last;
              }
          }
!         $libs .= $xlib . " ";
      }
!     $libs =~ s/ $//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
  
      my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
  
--- 510,527 ----
                  last;
              }
          }
!         $libs .= $xlib . $seperator;
      }
!     $libs =~ s/.$//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
+     return $libs;
+ }
+ 
+ sub WriteConfiguration
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ' ');
  
      my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
  
*************** sub Footer
*** 563,569 ****
      my ($self, $f) = @_;
  
      print $f <<EOF;
-  </Files>
   <Globals/>
  </VisualStudioProject>
  EOF
--- 584,589 ----
diff -Napcdr -x .git postgresql/src/tools/msvc/Solution.pm postgresql_dev/src/tools/msvc/Solution.pm
*** postgresql/src/tools/msvc/Solution.pm	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/Solution.pm	Wed Sep 28 19:26:02 2011
*************** package Solution;
*** 8,17 ****
  use Carp;
  use strict;
  use warnings;
  
! sub new
  {
!     my $junk = shift;
      my $options = shift;
      my $self = {
          projects => {},
--- 8,18 ----
  use Carp;
  use strict;
  use warnings;
+ use VSObjectFactory;
  
! sub _new
  {
!     my $classname = shift;
      my $options = shift;
      my $self = {
          projects => {},
*************** sub new
*** 21,27 ****
          vcver    => undef,
          platform => undef,
      };
!     bless $self;
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
--- 22,28 ----
          vcver    => undef,
          platform => undef,
      };
!     bless($self, $classname);
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
*************** sub new
*** 53,80 ****
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DetermineToolVersions();
  
      return $self;
  }
  
! sub DetermineToolVersions
  {
      my $self = shift;
  
-     # Determine version of vcbuild command, to set proper verison of visual studio
-     open(P,"vcbuild /? |") || die "vcbuild command not found";
-     my $line = <P>;
-     close(P);
-     if ($line !~ /^Microsoft\s*\(R\) Visual C\+\+ [^-]+ - \D+(\d+)\.00\.\d+/)
-     {
-         die "Unable to determine vcbuild version from first line of output!";
-     }
-     if ($1 == 8) { $self->{vcver} = '8.00' }
-     elsif ($1 == 9) { $self->{vcver} = '9.00' }
-     else { die "Unsupported version of Visual Studio: $1" }
-     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';
--- 54,68 ----
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DeterminePlatform();
  
      return $self;
  }
  
! sub DeterminePlatform
  {
      my $self = shift;
  
      # Determine if we are in 32 or 64-bit mode. Do this by seeing if CL has
      # 64-bit only parameters.
      $self->{platform} = 'Win32';
*************** sub AddProject
*** 428,434 ****
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = new Project($name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
--- 416,422 ----
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = VSObjectFactory::CreateProject($self->{vcver}, $name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
*************** sub Save
*** 488,495 ****
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version 9.00
! # Visual Studio 2005
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
--- 476,483 ----
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version $self->{solutionFileVersion}
! # $self->{visualStudioName}
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
*************** EOF
*** 497,503 ****
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}.vcproj", "$proj->{guid}"
  EndProject
  EOF
          }
--- 485,491 ----
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}$proj->{filenameExtension}", "$proj->{guid}"
  EndProject
  EOF
          }
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2005Project.pm postgresql_dev/src/tools/msvc/VC2005Project.pm
*** postgresql/src/tools/msvc/VC2005Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2005Project.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,25 ----
+ package VC2005Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2005 project file
+ #
+ # src/tools/msvc/VC2005Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '8.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2008Project.pm postgresql_dev/src/tools/msvc/VC2008Project.pm
*** postgresql/src/tools/msvc/VC2008Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2008Project.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,25 ----
+ package VC2008Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2008 project file
+ #
+ # src/tools/msvc/VC2008Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '9.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VC2010Project.pm postgresql_dev/src/tools/msvc/VC2010Project.pm
*** postgresql/src/tools/msvc/VC2010Project.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VC2010Project.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,368 ----
+ package VC2010Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2010 project file
+ #
+ # src/tools/msvc/VC2010Project.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '10.00';
+     $self->{filenameExtension} = '.vcxproj';
+ 
+     return $self;
+ }
+ 
+ sub AddDefine
+ {
+     my ($self, $def) = @_;
+ 
+     $self->{defines} .= $def . ';';
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+ 
+     my @references = @{$self->{references}};
+ 
+     if (scalar(@references))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $ref (@references)
+         {
+             print $f <<EOF;
+     <ProjectReference Include="$ref->{name}$ref->{filenameExtension}">
+       <Project>$ref->{guid}</Project>
+     </ProjectReference>
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+   <ItemGroup>
+ EOF
+     my @grammarFiles = ();
+     my @resourceFiles = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $fileName = $2;
+         if ($fileNameWithPath =~ /\.y$/ or $fileNameWithPath =~ /\.l$/)
+         {
+             push @grammarFiles, $fileNameWithPath;
+         }
+         elsif ($fileNameWithPath =~ /\.rc$/)
+         {
+             push @resourceFiles, $fileNameWithPath;
+         }
+         elsif (defined($uniquefiles{$fileName}))
+         {
+ 
+             # File already exists, so fake a new name
+             my $obj = $dir;
+             $obj =~ s/\\/_/g;
+ 
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath">
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">.\\debug\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">.\\release\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+     </ClCompile>
+ EOF
+         }
+         else
+         {
+             $uniquefiles{$fileName} = 1;
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath" />
+ EOF
+         }
+ 
+     }
+     print $f <<EOF;
+   </ItemGroup>
+ EOF
+     if (scalar(@grammarFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $grammarFile (@grammarFiles)
+         {
+             (my $outputFile = $grammarFile) =~ s/\.(y|l)$/.c/;
+             if ($grammarFile =~ /\.y$/)
+             {
+                 $outputFile =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+             else #if ($grammarFile =~ /\.l$/)
+             {
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+     if (scalar(@resourceFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $rcFile (@resourceFiles)
+         {
+             print $f <<EOF;
+     <ResourceCompile Include="$rcFile" />
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+   <ItemGroup Label="ProjectConfigurations">
+ EOF
+     $self->WriteConfigurationHeader($f, 'Debug');
+     $self->WriteConfigurationHeader($f, 'Release');
+     print $f <<EOF;
+   </ItemGroup>
+   <PropertyGroup Label="Globals">
+     <ProjectGuid>$self->{guid}</ProjectGuid>
+   </PropertyGroup>
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
+ EOF
+     $self->WriteConfigurationPropertyGroup($f, 'Release',{ wholeopt=>'false' });
+     $self->WriteConfigurationPropertyGroup($f, 'Debug',{ wholeopt=>'false' });
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.props" />
+   <ImportGroup Label="ExtensionSettings">
+   </ImportGroup>
+ EOF
+     $self->WritePropertySheetsPropertyGroup($f, 'Release');
+     $self->WritePropertySheetsPropertyGroup($f, 'Debug');
+     print $f <<EOF;
+   <PropertyGroup Label="UserMacros" />
+   <PropertyGroup>
+     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ EOF
+     $self->WriteAdditionalProperties($f, 'Debug');
+     $self->WriteAdditionalProperties($f, 'Release');
+     print $f <<EOF;
+   </PropertyGroup>
+ EOF
+     $self->WriteItemDefinitionGroup(
+         $f, 'Debug',
+         {
+             defs=>'_DEBUG;DEBUG=1;',
+             opt=>'Disabled',
+             strpool=>'false',
+             runtime=>'MultiThreadedDebugDLL'
+         }
+     );
+     $self->WriteItemDefinitionGroup($f, 'Release',
+         { defs=>'', opt=>'Full', strpool=>'true', runtime=>'MultiThreadedDLL' });
+ }
+ 
+ sub WriteConfigurationHeader
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <ProjectConfiguration Include="$cfgname|$self->{platform}">
+       <Configuration>$cfgname</Configuration>
+       <Platform>$self->{platform}</Platform>
+     </ProjectConfiguration>
+ EOF
+ }
+ 
+ sub WriteConfigurationPropertyGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+ 
+     print $f <<EOF;
+   <PropertyGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="Configuration">
+     <ConfigurationType>$cfgtype</ConfigurationType>
+     <UseOfMfc>false</UseOfMfc>
+     <CharacterSet>MultiByte</CharacterSet>
+     <WholeProgramOptimization>$p->{wholeopt}</WholeProgramOptimization>
+   </PropertyGroup>
+ EOF
+ }
+ 
+ sub WritePropertySheetsPropertyGroup
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+   <ImportGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="PropertySheets">
+     <Import Project="\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props" Condition="exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')" Label="LocalAppDataPlatform" />
+   </ImportGroup>
+ EOF
+ }
+ 
+ sub WriteAdditionalProperties
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <OutDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</OutDir>
+     <IntDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</IntDir>
+     <LinkIncremental Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">false</LinkIncremental>
+ EOF
+ }
+ 
+ sub WriteItemDefinitionGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+ 
+     my $includes = $self->{includes};
+     unless ($includes eq '' or $includes =~ /;$/)
+     {
+         $includes .= ';';
+     }
+     print $f <<EOF;
+   <ItemDefinitionGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">
+     <ClCompile>
+       <Optimization>$p->{opt}</Optimization>
+       <AdditionalIncludeDirectories>$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$includes\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+       <PreprocessorDefinitions>WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}\%(PreprocessorDefinitions)</PreprocessorDefinitions>
+       <StringPooling>$p->{strpool}</StringPooling>
+       <RuntimeLibrary>$p->{runtime}</RuntimeLibrary>
+       <DisableSpecificWarnings>$self->{disablewarnings};\%(DisableSpecificWarnings)</DisableSpecificWarnings>
+       <AdditionalOptions>/MP \%(AdditionalOptions)</AdditionalOptions>
+       <AssemblerOutput>
+       </AssemblerOutput>
+       <AssemblerListingLocation>.\\$cfgname\\$self->{name}\\</AssemblerListingLocation>
+       <ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
+       <ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
+       <BrowseInformation>false</BrowseInformation>
+       <WarningLevel>Level3</WarningLevel>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+       <CompileAs>Default</CompileAs>
+     </ClCompile>
+     <Link>
+       <OutputFile>.\\$cfgname\\$self->{name}\\$self->{name}.$self->{type}</OutputFile>
+       <AdditionalDependencies>$libs;\%(AdditionalDependencies)</AdditionalDependencies>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <AdditionalLibraryDirectories>\%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+       <IgnoreSpecificDefaultLibraries>libc;\%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+       <StackReserveSize>4194304</StackReserveSize>
+       <GenerateDebugInformation>true</GenerateDebugInformation>
+       <ProgramDatabaseFile>.\\$cfgname\\$self->{name}\\$self->{name}.pdb</ProgramDatabaseFile>
+       <GenerateMapFile>false</GenerateMapFile>
+       <MapFileName>.\\$cfgname\\$self->{name}\\$self->{name}.map</MapFileName>
+       <SubSystem>Console</SubSystem>
+       <TargetMachine>$targetmachine</TargetMachine>
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f
+ "      <AdditionalOptions>/ignore:$self->{disablelinkerwarnings} \%(AdditionalOptions)</AdditionalOptions>\n";
+     }
+     if ($self->{implib})
+     {
+         my $l = $self->{implib};
+         $l =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ImportLibrary>$l</ImportLibrary>\n";
+     }
+     if ($self->{def})
+     {
+         my $d = $self->{def};
+         $d =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ModuleDefinitionFile>$d</ModuleDefinitionFile>\n";
+     }
+     print $f <<EOF;
+     </Link>
+     <ResourceCompile>
+       <AdditionalIncludeDirectories>src\\include;\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+     </ResourceCompile>
+ EOF
+     if ($self->{builddef})
+     {
+         print $f <<EOF;
+     <PreLinkEvent>
+       <Message>Generate DEF file</Message>
+       <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+     </PreLinkEvent>
+ EOF
+     }
+     print $f <<EOF;
+   </ItemDefinitionGroup>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+     $self->WriteReferences($f);
+ 
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.targets" />
+   <ImportGroup Label="ExtensionTargets">
+   </ImportGroup>
+ </Project>
+ EOF
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2005Solution.pm postgresql_dev/src/tools/msvc/VS2005Solution.pm
*** postgresql/src/tools/msvc/VS2005Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2005Solution.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2005Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2005 solution file
+ #
+ # src/tools/msvc/VS2005Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '9.00';
+     $self->{vcver} = '8.00';
+     $self->{visualStudioName} = 'Visual Studio 2005';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2008Solution.pm postgresql_dev/src/tools/msvc/VS2008Solution.pm
*** postgresql/src/tools/msvc/VS2008Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2008Solution.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2008Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2008 solution file
+ #
+ # src/tools/msvc/VS2008Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '10.00';
+     $self->{vcver} = '9.00';
+     $self->{visualStudioName} = 'Visual Studio 2008';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VS2010Solution.pm postgresql_dev/src/tools/msvc/VS2010Solution.pm
*** postgresql/src/tools/msvc/VS2010Solution.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VS2010Solution.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,27 ----
+ package VS2010Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2010 solution file
+ #
+ # src/tools/msvc/VS2010Solution.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '11.00';
+     $self->{vcver} = '10.00';
+     $self->{visualStudioName} = 'Visual Studio 2010';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VSObjectFactory.pm postgresql_dev/src/tools/msvc/VSObjectFactory.pm
*** postgresql/src/tools/msvc/VSObjectFactory.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VSObjectFactory.pm	Wed Sep 28 19:26:02 2011
***************
*** 0 ****
--- 1,126 ----
+ package VSObjectFactory;
+ 
+ #
+ # Package that creates Visual Studio wrapper objects for msvc build
+ #
+ # src/tools/msvc/VSObjectFactory.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ 
+ use Exporter;
+ use Project;
+ use Solution;
+ use VC2005Project;
+ use VC2008Project;
+ use VC2010Project;
+ use VS2005Solution;
+ use VS2008Solution;
+ use VS2010Solution;
+ 
+ our (@ISA, @EXPORT_OK);
+ @ISA = qw(Exporter);
+ @EXPORT_OK = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
+ 
+ sub CreateSolution
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VS2005Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VS2008Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VS2010Solution(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub CreateProject
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VC2005Project(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VC2008Project(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VC2010Project(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub DetermineVisualStudioVersion
+ {
+     my $nmakeVersion = shift;
+ 
+     if (!defined($nmakeVersion))
+     {
+ 
+         # Determine version of nmake command, to set proper verison of visual studio
+         # we use nmake as it has existed for a long time and still exists in visual studio 2010
+         open(P,"nmake /? 2>&1 |")
+           || croak "Unable to determine Visual Studio version: The nmake command wasn't found.";
+         while(<P>)
+         {
+             chomp;
+             if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+             {
+                 return _GetVisualStudioVersion($1, $2);
+             }
+         }
+         close(P);
+     }
+     elsif($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+     {
+         return _GetVisualStudioVersion($1, $2);
+     }
+     croak "Unable to determine Visual Studio version: The nmake version could not be determined.";
+ }
+ 
+ sub _GetVisualStudioVersion
+ {
+     my($major, $minor) = @_;
+     if ($major > 10)
+     {
+         carp
+ "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
+         return '10.00';
+     }
+     elsif ($major < 6)
+     {
+         croak
+ "Unable to determine Visual Studio version: Visual Studio versions before 6.0 aren't supported.";
+     }
+     return "$major.$minor";
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/build.pl postgresql_dev/src/tools/msvc/build.pl
*** postgresql/src/tools/msvc/build.pl	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/build.pl	Wed Sep 28 19:26:02 2011
*************** our $config;
*** 33,39 ****
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
--- 33,39 ----
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! my $vcver = Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
*************** elsif ($ARGV[0] ne "RELEASE")
*** 50,56 ****
  
  # ... and do it
  
! if ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
--- 50,60 ----
  
  # ... and do it
  
! if ($buildwhat and $vcver eq '10.00')
! {
!     system("msbuild $buildwhat.vcxproj /verbosity:detailed /p:Configuration=$bconf");
! }
! elsif ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
diff -Napcdr -x .git postgresql/src/tools/msvc/builddoc.pl postgresql_dev/src/tools/msvc/builddoc.pl
*** postgresql/src/tools/msvc/builddoc.pl	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/builddoc.pl	Wed Sep 28 19:26:02 2011
*************** $cmd =
*** 69,76 ****
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
!   ."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
--- 69,76 ----
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd =
!   "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
diff -Napcdr -x .git postgresql/src/tools/msvc/clean.bat postgresql_dev/src/tools/msvc/clean.bat
*** postgresql/src/tools/msvc/clean.bat	Mon Aug 15 18:08:31 2011
--- postgresql_dev/src/tools/msvc/clean.bat	Wed Sep 28 19:26:02 2011
*************** if exist ..\msvc if exist ..\..\..\src c
*** 10,17 ****
--- 10,21 ----
  if exist debug rd /s /q debug
  if exist release rd /s /q release
  for %%f in (*.vcproj) do del %%f
+ for %%f in (*.vcxproj) do del %%f
+ for %%f in (*.vcxproj.user) do del %%f
  if exist pgsql.sln del /q pgsql.sln
  if exist pgsql.sln.cache del /q pgsql.sln.cache
+ if exist pgsql.sdf del /q pgsql.sdf
+ if exist pgsql.suo del /q /a:H pgsql.suo
  del /s /q src\bin\win32ver.rc 2> NUL
  del /s /q src\interfaces\win32ver.rc 2> NUL
  if exist src\backend\win32ver.rc del /q src\backend\win32ver.rc
#19Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#18)
Re: Review of VS 2010 support patches

On 09/28/2011 03:53 PM, Brar Piening wrote:

Brar Piening wrote:

The attached patch includes documentation changes and excludes my
versions of pgbison.pl and pgflex.pl which have been replaced by
Andrews' versions that are already commited.

Building current head today I noticed that the patch doesn't apply
cleanly anymore.

Attached is a new version.

This patch looks OK in principle.

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why not
just stash all the packages in Solution.pm and Project.pm? Also, instead
of doing this in Mkvcbuild.pm:

my $vsVersion = VSObjectFactory::DetermineVisualStudioVersion();
$solution = VSObjectFactory::CreateSolution($vsVersion, $config);

why not just add "use VSObjectFactory;" at the top of the file and
import these into the current namespace, just as we do for pretty much
everything else?

There are some stylistic things that aren't the way I usually do things
(use of named instead of anonymous file handles, use of heredocs instead
of qq{} style quotes) and that I would prefer done differently, but
those are more matters of taste than substance. I also generally dislike
composing XML by non-formal means, as it can be quite error prone and
often leads to errors in unforeseen corner cases. But in this case we
certainly don't want to impose an extra requirement on some perl XML
module, and it would make this code terribly verbose, so we just have to
hope we get it right :-)

I don't have a VS2010 machine available to test it on unfortunately.
I'll see what I can do about arranging one, at least temporarily.
Meanwhile I'll test it on my VS2005 and VS2008 machines to make sure it
doesn't break anything.

cheers

andrew

#20Brar Piening
brar@gmx.de
In reply to: Andrew Dunstan (#19)
Re: Review of VS 2010 support patches

Andrew Dunstan wrote:

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why not
just stash all the packages in Solution.pm and Project.pm?

We certainly don't *need* them.
Having different files separates the tasks of generating different
target file formats into different source files. In my opinion this
makes it easier to find the code that is actually generating the files
that get used in a specific build environment.
While the VSnnnnSolution.pm and VC200nProject.pm files are indeed not
much more than stubs that could eventually be extended in future (and
probably never will) VC2010Project.pm contains the whole code for
generating the new file format which would significantly bloat up the
code in Project.pm that currently contains the common code for
generating the old file formats.

Anyhow - this is just my opinion and my intention is to help improving
the Windows build process and not forcing my design into the project.

Also, instead of doing this in Mkvcbuild.pm:

my $vsVersion = VSObjectFactory::DetermineVisualStudioVersion();
$solution = VSObjectFactory::CreateSolution($vsVersion, $config);

why not just add "use VSObjectFactory;" at the top of the file and
import these into the current namespace, just as we do for pretty much
everything else?

Yes - my way (singleton, clean namespace) is probably overengineering in
this context.

There are some stylistic things that aren't the way I usually do
things (use of named instead of anonymous file handles, use of
heredocs instead of qq{} style quotes) and that I would prefer done
differently, but those are more matters of taste than substance.

Please go ahead and change it to whatever style you prefer. There is
certainly more than one way to style it ;-)

I also generally dislike composing XML by non-formal means, as it can
be quite error prone and often leads to errors in unforeseen corner
cases. But in this case we certainly don't want to impose an extra
requirement on some perl XML module, and it would make this code
terribly verbose, so we just have to hope we get it right :-)

I actually had a look into the default ActivePerl docs to find out
whether there is a better way for generating xml, but as there is no
XML-generator package in the default distribution I decided not to
introduce a new dependency.

Thanks for your feedback.

Regards,

Brar

#21Andrew Dunstan
adunstan@postgresql.org
In reply to: Andrew Dunstan (#19)
Re: Review of VS 2010 support patches

On 11/29/2011 10:01 AM, Andrew Dunstan wrote:

I don't have a VS2010 machine available to test it on unfortunately.
I'll see what I can do about arranging one, at least temporarily.
Meanwhile I'll test it on my VS2005 and VS2008 machines to make sure
it doesn't break anything.

I can confirm that it does work on my 2005 and 2008 platforms.

cheers

andrew

#22Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#20)
Re: Review of VS 2010 support patches

On 11/29/2011 04:32 PM, Brar Piening wrote:

Andrew Dunstan wrote:

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why not
just stash all the packages in Solution.pm and Project.pm?

We certainly don't *need* them.
Having different files separates the tasks of generating different
target file formats into different source files. In my opinion this
makes it easier to find the code that is actually generating the files
that get used in a specific build environment.
While the VSnnnnSolution.pm and VC200nProject.pm files are indeed not
much more than stubs that could eventually be extended in future (and
probably never will) VC2010Project.pm contains the whole code for
generating the new file format which would significantly bloat up the
code in Project.pm that currently contains the common code for
generating the old file formats.

Does anyone else have an opinion on this. I want to wrap this up ASAP so
we can get a VS2010 buildfarm member working.

cheers

andrew

#23Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#22)
Re: Review of VS 2010 support patches

On Thu, Dec 1, 2011 at 01:06, Andrew Dunstan <andrew@dunslane.net> wrote:

On 11/29/2011 04:32 PM, Brar Piening wrote:

Andrew Dunstan wrote:

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why not just
stash all the packages in Solution.pm and Project.pm?

We certainly don't *need* them.
Having different files separates the tasks of generating different target
file formats into different source files. In my opinion this makes it easier
to find the code that is actually generating the files that get used in a
specific build environment.
While the VSnnnnSolution.pm and VC200nProject.pm files are indeed not much
more than stubs that could eventually be extended in future (and probably
never will) VC2010Project.pm contains the whole code for generating the new
file format which would significantly bloat up the code in Project.pm that
currently contains the common code for generating the old file formats.

Does anyone else have an opinion on this. I want to wrap this up ASAP so we
can get a VS2010 buildfarm member working.

I guess the most likely one would be me, but not really. My perl-fu is
well below this level, so I will happily +1 whatever you more
experienced perl guys say :-) I don't see a big problem with a couple
of more files - it's not like we're going to support 20 different
versions of VS anyway, once we get to 4 i'm sure the earliest one is
well out of support already and can be removed. But in summary I'd
vote for whatever matches the "general perl pest practices" at this
time.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#24Brar Piening
brar@gmx.de
In reply to: Magnus Hagander (#23)
Re: Review of VS 2010 support patches

Magnus Hagander wrote:

I'd vote for whatever matches the "general perl pest practices" at
this time.

I didn't kow the "perl pest practices" until now but as the PostgreSQL
community is more into C I think I know what you mean ;-)

#25Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#20)
Re: Review of VS 2010 support patches

On 11/29/2011 04:32 PM, Brar Piening wrote:

Andrew Dunstan wrote:

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why not
just stash all the packages in Solution.pm and Project.pm?

We certainly don't *need* them.
Having different files separates the tasks of generating different
target file formats into different source files. In my opinion this
makes it easier to find the code that is actually generating the files
that get used in a specific build environment.
While the VSnnnnSolution.pm and VC200nProject.pm files are indeed not
much more than stubs that could eventually be extended in future (and
probably never will) VC2010Project.pm contains the whole code for
generating the new file format which would significantly bloat up the
code in Project.pm that currently contains the common code for
generating the old file formats.

Anyhow - this is just my opinion and my intention is to help improving
the Windows build process and not forcing my design into the project.

Well, I do also dislike the asymmetry of it. Here's what I suggest: for
the Solution files, we'll just put the object packages in Solution.pm.
There really doesn't seem like any need for those to have tiny files on
their own. For the Project files, factor out the 2005/2008 specific
parts from Project.pm into a new file, and have a new file for the
equivalent parts of your new VC2010Project.pm. Then we'll add packages
to Project.pm to create objects just like I'm suggesting above for
Solution.pm. The result is then more symmetrical and we'll have three
new files instead of seven (counting VSObjectFactory.pm).

Perhaps, too, this has all got sufficiently complicated that adding
some descritpion of what's going on here to README would be in order. I
suspect some of my fellow committers tend to look at the whole thing and
scratch their heads a bit, and that means expecting other people to make
sense if it is probably a bit much ;-)

cheers

andrew

#26Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#25)
Re: Review of VS 2010 support patches

On 12/04/2011 12:44 PM, Andrew Dunstan wrote:

On 11/29/2011 04:32 PM, Brar Piening wrote:

Andrew Dunstan wrote:

Some minor nitpicks:

Do we really need to create all those VSnnnnProject.pm and
VSnnnnSolution.pm files? They are all always included anyway. Why
not just stash all the packages in Solution.pm and Project.pm?

We certainly don't *need* them.
Having different files separates the tasks of generating different
target file formats into different source files. In my opinion this
makes it easier to find the code that is actually generating the
files that get used in a specific build environment.
While the VSnnnnSolution.pm and VC200nProject.pm files are indeed not
much more than stubs that could eventually be extended in future (and
probably never will) VC2010Project.pm contains the whole code for
generating the new file format which would significantly bloat up the
code in Project.pm that currently contains the common code for
generating the old file formats.

Anyhow - this is just my opinion and my intention is to help
improving the Windows build process and not forcing my design into
the project.

Well, I do also dislike the asymmetry of it. Here's what I suggest:
for the Solution files, we'll just put the object packages in
Solution.pm. There really doesn't seem like any need for those to have
tiny files on their own. For the Project files, factor out the
2005/2008 specific parts from Project.pm into a new file, and have a
new file for the equivalent parts of your new VC2010Project.pm. Then
we'll add packages to Project.pm to create objects just like I'm
suggesting above for Solution.pm. The result is then more symmetrical
and we'll have three new files instead of seven (counting
VSObjectFactory.pm).

Perhaps, too, this has all got sufficiently complicated that adding
some descritpion of what's going on here to README would be in order.
I suspect some of my fellow committers tend to look at the whole thing
and scratch their heads a bit, and that means expecting other people
to make sense if it is probably a bit much ;-)

In the absence of reaction to this I've marked the patch as "waiting on
author", but if/when I have time I'll work on rearranging things as above.

cheers

andrew

#27Brar Piening
brar@gmx.de
In reply to: Andrew Dunstan (#26)
Re: Review of VS 2010 support patches

Andrew Dunstan wrote:

In the absence of reaction to this I've marked the patch as "waiting
on author", but if/when I have time I'll work on rearranging things as
above.

Sorry for my non-reaction.

I'm currently trying to find some time window in my before chrismas
schedule but it seems like I can't guarantee anything.

Anyhow I'll try to make it happen within "this year".

Regards,

Brar

#28Greg Smith
greg@2ndQuadrant.com
In reply to: Brar Piening (#27)
Re: Review of VS 2010 support patches

On 12/10/2011 12:58 PM, Brar Piening wrote:

I'm currently trying to find some time window in my before chrismas
schedule but it seems like I can't guarantee anything.

Anyhow I'll try to make it happen within "this year".

That's fair, and Andrew or something else may get an itch to just plow
forward and do it themselves. I'm going to mark this one returned with
feedback for now. So long as we get an update from you before the
January 15th CommitFest, this should still be feasible to slip into 9.2.

--
Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us

#29Brar Piening
brar@gmx.de
In reply to: Andrew Dunstan (#25)
1 attachment(s)
Re: Review of VS 2010 support patches

Andrew Dunstan wrote:

Well, I do also dislike the asymmetry of it. Here's what I suggest:
for the Solution files, we'll just put the object packages in
Solution.pm. There really doesn't seem like any need for those to have
tiny files on their own. For the Project files, factor out the
2005/2008 specific parts from Project.pm into a new file, and have a
new file for the equivalent parts of your new VC2010Project.pm. Then
we'll add packages to Project.pm to create objects just like I'm
suggesting above for Solution.pm. The result is then more symmetrical
and we'll have three new files instead of seven (counting
VSObjectFactory.pm).

Perhaps, too, this has all got sufficiently complicated that adding
some descritpion of what's going on here to README would be in order.
I suspect some of my fellow committers tend to look at the whole thing
and scratch their heads a bit, and that means expecting other people
to make sense if it is probably a bit much ;-)

Attached is an updated patch which includes your suggestions.

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual
Studio 2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that
breaks postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking anythig
else.

Regards,

Brar

Attachments:

VS2010v11.patchtext/plain; name=VS2010v11.patchDownload
diff -Napcdr -x .git postgresql/doc/src/sgml/install-windows.sgml postgresql_dev/doc/src/sgml/install-windows.sgml
*** postgresql/doc/src/sgml/install-windows.sgml	Sun Dec 25 20:45:34 2011
--- postgresql_dev/doc/src/sgml/install-windows.sgml	Mon Dec 26 11:02:25 2011
***************
*** 20,29 ****
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Platform SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005 or 2008</productname>. In some cases
!   that requires the installation of the <productname>Platform SDK</productname>
    in addition to the compiler.
   </para>
  
--- 20,29 ----
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Windows SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005, 2008 or 2010</productname>. In some cases
!   that requires the installation of the <productname>Windows SDK</productname>
    in addition to the compiler.
   </para>
  
***************
*** 69,100 ****
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Platform SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Platform SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way us to use the compilers in the <productname>Platform SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL supports the compilers from
!   <productname>Visual Studio 2005</productname> and
!   <productname>Visual Studio 2008</productname>. When using the Platform SDK
!   only, or when building for 64-bit Windows, only
!   <productname>Visual Studio 2008</productname> is supported.
!   <productname>Visual Studio 2010</productname> is not yet supported.
!  </para>
! 
!  <para>
!   When building using the <productname>Platform SDK</productname>, versions
!   6.0 to 7.0 of the SDK are supported. Older or newer versions will not work.
!   In particular, versions from 7.0a and later will not work, since
!   they include compilers from <productname>Visual Studio 2010</productname>.
   </para>
  
   <para>
--- 69,94 ----
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Microsoft Windows SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Microsoft Windows SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way is to use the compilers in the <productname>Windows SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL is known to support compilation using the compilers shipped with
!   <productname>Visual Studio 2005</productname> to
!   <productname>Visual Studio 2010</productname> (including Express editions),
!   as well as standalone Windows SDK releases 6.0 to 7.1.
!   64-bit PostgreSQL builds are only supported with
!   <productname>Microsoft Windows SDK</productname> version 6.0a and above or
!   <productname>Visual Studio 2008</productname> and above.
   </para>
  
   <para>
***************
*** 104,114 ****
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>. In the
!   <productname>Platform SDK</productname>, start the
!   <application>CMD shell</application> listed under the SDK on the Start Menu.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
--- 98,110 ----
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
+   In the <productname>Microsoft Windows SDK</productname>, start the
+   <application>CMD shell</application> listed under the SDK on the Start Menu.
+   In recent SDK versions you can change the targeted CPU architecture by using
+   the <command>setenv</command> command.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 148,164 ****
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Platform SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Platform SDK</productname> (currently
!       version 7.0), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Platform SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
--- 144,160 ----
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Windows SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Windows SDK</productname> (currently
!       version 7.1), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Windows SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 202,207 ****
--- 198,207 ----
        Bison can be downloaded from <ulink url="http://gnuwin32.sourceforge.net"></>.
        Flex can be downloaded from
        <ulink url="http://www.postgresql.org/ftp/misc/winflex/"></>.
+       If you are using <productname>msysGit</productname> for accessing the
+       PostgreSQL <productname>Git</productname> repository you probably already
+       have recent versions of bison and flex in your <productname>Git</productname>
+       binary directory.
       </para>
  
       <note>
*************** $ENV{DOCROOT}='c:\docbook';
*** 479,485 ****
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Platform SDK</productname> method is recommended.
   </para>
  
   <para>
--- 479,485 ----
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Windows SDK</productname> method is recommended.
   </para>
  
   <para>
diff -Napcdr -x .git postgresql/src/tools/msvc/Install.pm postgresql_dev/src/tools/msvc/Install.pm
*** postgresql/src/tools/msvc/Install.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Install.pm	Mon Dec 26 20:14:30 2011
*************** sub Install
*** 56,66 ****
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories(
!         $target, 'bin', 'lib', 'share',
!         'share/timezonesets','share/extension', 'share/contrib','doc',
!         'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
!     );
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
--- 56,63 ----
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories($target, 'bin', 'lib', 'share','share/timezonesets','share/extension',
!         'share/contrib','doc','doc/extension', 'doc/contrib','symbols', 'share/tsearch_data');
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
*************** sub CopySolutionOutput
*** 186,191 ****
--- 183,195 ----
      my $rem = qr{Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"\) = "([^"]+)"};
  
      my $sln = read_file("pgsql.sln") || croak "Could not open pgsql.sln\n";
+ 
+     my $vcproj = 'vcproj';
+     if ($sln =~ /Microsoft Visual Studio Solution File, Format Version (\d+)\.\d+/ && $1 >= 11)
+     {
+         $vcproj = 'vcxproj';
+     }
+ 
      print "Copying build output files...";
      while ($sln =~ $rem)
      {
*************** sub CopySolutionOutput
*** 195,220 ****
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.vcproj") || croak "Could not open $pf.vcproj\n";
!         if ($proj !~ qr{ConfigurationType="([^"]+)"})
!         {
!             croak "Could not parse $pf.vcproj\n";
!         }
!         if ($1 == 1)
          {
!             $dir = "bin";
!             $ext = "exe";
          }
!         elsif ($1 == 2)
          {
!             $dir = "lib";
!             $ext = "dll";
          }
          else
          {
! 
!             # Static lib, such as libpgport, only used internally during build, don't install
!             next;
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
--- 199,246 ----
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.$vcproj") || croak "Could not open $pf.$vcproj\n";
!         if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
          {
!             if ($1 == 1)
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 == 2)
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
!         elsif ($vcproj eq 'vcxproj' && $proj =~ qr{<ConfigurationType>(\w+)</ConfigurationType>})
          {
!             if ($1 eq 'Application')
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 eq 'DynamicLibrary')
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else # 'StaticLibrary'
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
          else
          {
!             croak "Could not parse $pf.$vcproj\n";
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
*************** sub CopyIncludeFiles
*** 470,477 ****
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
!         'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
--- 496,502 ----
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/','gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
diff -Napcdr -x .git postgresql/src/tools/msvc/MSBuildProject.pm postgresql_dev/src/tools/msvc/MSBuildProject.pm
*** postgresql/src/tools/msvc/MSBuildProject.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/MSBuildProject.pm	Mon Dec 26 20:14:30 2011
***************
*** 0 ****
--- 1,388 ----
+ package MSBuildProject;
+ 
+ #
+ # Package that encapsulates a MSBuild (Visual C++ 2010) project file
+ #
+ # src/tools/msvc/MSBuildProject.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub _new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{filenameExtension} = '.vcxproj';
+ 
+     return $self;
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+   <ItemGroup Label="ProjectConfigurations">
+ EOF
+     $self->WriteConfigurationHeader($f, 'Debug');
+     $self->WriteConfigurationHeader($f, 'Release');
+     print $f <<EOF;
+   </ItemGroup>
+   <PropertyGroup Label="Globals">
+     <ProjectGuid>$self->{guid}</ProjectGuid>
+   </PropertyGroup>
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
+ EOF
+     $self->WriteConfigurationPropertyGroup($f, 'Release',{ wholeopt=>'false' });
+     $self->WriteConfigurationPropertyGroup($f, 'Debug',{ wholeopt=>'false' });
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.props" />
+   <ImportGroup Label="ExtensionSettings">
+   </ImportGroup>
+ EOF
+     $self->WritePropertySheetsPropertyGroup($f, 'Release');
+     $self->WritePropertySheetsPropertyGroup($f, 'Debug');
+     print $f <<EOF;
+   <PropertyGroup Label="UserMacros" />
+   <PropertyGroup>
+     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ EOF
+     $self->WriteAdditionalProperties($f, 'Debug');
+     $self->WriteAdditionalProperties($f, 'Release');
+     print $f <<EOF;
+   </PropertyGroup>
+ EOF
+     $self->WriteItemDefinitionGroup(
+         $f, 'Debug',
+         {
+             defs=>'_DEBUG;DEBUG=1;',
+             opt=>'Disabled',
+             strpool=>'false',
+             runtime=>'MultiThreadedDebugDLL'
+         }
+     );
+     $self->WriteItemDefinitionGroup($f, 'Release',
+         { defs=>'', opt=>'Full', strpool=>'true', runtime=>'MultiThreadedDLL' });
+ }
+ 
+ sub AddDefine
+ {
+     my ($self, $def) = @_;
+ 
+     $self->{defines} .= $def . ';';
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+ 
+     my @references = @{$self->{references}};
+ 
+     if (scalar(@references))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $ref (@references)
+         {
+             print $f <<EOF;
+     <ProjectReference Include="$ref->{name}$ref->{filenameExtension}">
+       <Project>$ref->{guid}</Project>
+     </ProjectReference>
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+   <ItemGroup>
+ EOF
+     my @grammarFiles = ();
+     my @resourceFiles = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $fileName = $2;
+         if ($fileNameWithPath =~ /\.y$/ or $fileNameWithPath =~ /\.l$/)
+         {
+             push @grammarFiles, $fileNameWithPath;
+         }
+         elsif ($fileNameWithPath =~ /\.rc$/)
+         {
+             push @resourceFiles, $fileNameWithPath;
+         }
+         elsif (defined($uniquefiles{$fileName}))
+         {
+ 
+             # File already exists, so fake a new name
+             my $obj = $dir;
+             $obj =~ s/\\/_/g;
+ 
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath">
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">.\\debug\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">.\\release\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+     </ClCompile>
+ EOF
+         }
+         else
+         {
+             $uniquefiles{$fileName} = 1;
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath" />
+ EOF
+         }
+ 
+     }
+     print $f <<EOF;
+   </ItemGroup>
+ EOF
+     if (scalar(@grammarFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $grammarFile (@grammarFiles)
+         {
+             (my $outputFile = $grammarFile) =~ s/\.(y|l)$/.c/;
+             if ($grammarFile =~ /\.y$/)
+             {
+                 $outputFile =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+             else #if ($grammarFile =~ /\.l$/)
+             {
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+     if (scalar(@resourceFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $rcFile (@resourceFiles)
+         {
+             print $f <<EOF;
+     <ResourceCompile Include="$rcFile" />
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteConfigurationHeader
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <ProjectConfiguration Include="$cfgname|$self->{platform}">
+       <Configuration>$cfgname</Configuration>
+       <Platform>$self->{platform}</Platform>
+     </ProjectConfiguration>
+ EOF
+ }
+ 
+ sub WriteConfigurationPropertyGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+ 
+     print $f <<EOF;
+   <PropertyGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="Configuration">
+     <ConfigurationType>$cfgtype</ConfigurationType>
+     <UseOfMfc>false</UseOfMfc>
+     <CharacterSet>MultiByte</CharacterSet>
+     <WholeProgramOptimization>$p->{wholeopt}</WholeProgramOptimization>
+   </PropertyGroup>
+ EOF
+ }
+ 
+ sub WritePropertySheetsPropertyGroup
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+   <ImportGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="PropertySheets">
+     <Import Project="\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props" Condition="exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')" Label="LocalAppDataPlatform" />
+   </ImportGroup>
+ EOF
+ }
+ 
+ sub WriteAdditionalProperties
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <OutDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</OutDir>
+     <IntDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</IntDir>
+     <LinkIncremental Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">false</LinkIncremental>
+ EOF
+ }
+ 
+ sub WriteItemDefinitionGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+ 
+     my $includes = $self->{includes};
+     unless ($includes eq '' or $includes =~ /;$/)
+     {
+         $includes .= ';';
+     }
+     print $f <<EOF;
+   <ItemDefinitionGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">
+     <ClCompile>
+       <Optimization>$p->{opt}</Optimization>
+       <AdditionalIncludeDirectories>$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$includes\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+       <PreprocessorDefinitions>WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}\%(PreprocessorDefinitions)</PreprocessorDefinitions>
+       <StringPooling>$p->{strpool}</StringPooling>
+       <RuntimeLibrary>$p->{runtime}</RuntimeLibrary>
+       <DisableSpecificWarnings>$self->{disablewarnings};\%(DisableSpecificWarnings)</DisableSpecificWarnings>
+       <AdditionalOptions>/MP \%(AdditionalOptions)</AdditionalOptions>
+       <AssemblerOutput>
+       </AssemblerOutput>
+       <AssemblerListingLocation>.\\$cfgname\\$self->{name}\\</AssemblerListingLocation>
+       <ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
+       <ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
+       <BrowseInformation>false</BrowseInformation>
+       <WarningLevel>Level3</WarningLevel>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+       <CompileAs>Default</CompileAs>
+     </ClCompile>
+     <Link>
+       <OutputFile>.\\$cfgname\\$self->{name}\\$self->{name}.$self->{type}</OutputFile>
+       <AdditionalDependencies>$libs;\%(AdditionalDependencies)</AdditionalDependencies>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <AdditionalLibraryDirectories>\%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+       <IgnoreSpecificDefaultLibraries>libc;\%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+       <StackReserveSize>4194304</StackReserveSize>
+       <GenerateDebugInformation>true</GenerateDebugInformation>
+       <ProgramDatabaseFile>.\\$cfgname\\$self->{name}\\$self->{name}.pdb</ProgramDatabaseFile>
+       <GenerateMapFile>false</GenerateMapFile>
+       <MapFileName>.\\$cfgname\\$self->{name}\\$self->{name}.map</MapFileName>
+       <SubSystem>Console</SubSystem>
+       <TargetMachine>$targetmachine</TargetMachine>
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f
+ "      <AdditionalOptions>/ignore:$self->{disablelinkerwarnings} \%(AdditionalOptions)</AdditionalOptions>\n";
+     }
+     if ($self->{implib})
+     {
+         my $l = $self->{implib};
+         $l =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ImportLibrary>$l</ImportLibrary>\n";
+     }
+     if ($self->{def})
+     {
+         my $d = $self->{def};
+         $d =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ModuleDefinitionFile>$d</ModuleDefinitionFile>\n";
+     }
+     print $f <<EOF;
+     </Link>
+     <ResourceCompile>
+       <AdditionalIncludeDirectories>src\\include;\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+     </ResourceCompile>
+ EOF
+     if ($self->{builddef})
+     {
+         print $f <<EOF;
+     <PreLinkEvent>
+       <Message>Generate DEF file</Message>
+       <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+     </PreLinkEvent>
+ EOF
+     }
+     print $f <<EOF;
+   </ItemDefinitionGroup>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+     $self->WriteReferences($f);
+ 
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.targets" />
+   <ImportGroup Label="ExtensionTargets">
+   </ImportGroup>
+ </Project>
+ EOF
+ }
+ 
+ package VC2010Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2010 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(MSBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '10.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/Mkvcbuild.pm postgresql_dev/src/tools/msvc/Mkvcbuild.pm
*** postgresql/src/tools/msvc/Mkvcbuild.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Mkvcbuild.pm	Mon Dec 26 20:14:30 2011
*************** use Solution;
*** 14,19 ****
--- 14,20 ----
  use Cwd;
  use File::Copy;
  use Config;
+ use VSObjectFactory;
  use List::Util qw(first);
  
  use Exporter;
*************** sub mkvcbuild
*** 47,53 ****
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     $solution = new Solution($config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
--- 48,56 ----
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     my $vsVersion = DetermineVisualStudioVersion();
! 
!     $solution = CreateSolution($vsVersion, $config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
*************** sub mkvcbuild
*** 344,355 ****
      $pgdump->AddFile('src\backend\parser\kwlookup.c');
  
      my $pgdumpall = AddSimpleFrontend('pg_dump', 1);
! 	# pg_dumpall doesn't use the files in the Makefile's $(OBJS), unlike
! 	# pg_dump and pg_restore.
! 	# So remove their sources from the object, keeping the other setup that 
! 	# AddSimpleFrontend() has done.
!     my @nodumpall = grep  { m/src\\bin\\pg_dump\\.*\.c$/ } 
! 	keys %{$pgdumpall->{files}};
      delete @{$pgdumpall->{files}}{@nodumpall};
      $pgdumpall->{name} = 'pg_dumpall';
      $pgdumpall->AddIncludeDir('src\backend');
--- 347,359 ----
      $pgdump->AddFile('src\backend\parser\kwlookup.c');
  
      my $pgdumpall = AddSimpleFrontend('pg_dump', 1);
! 
!     # pg_dumpall doesn't use the files in the Makefile's $(OBJS), unlike
!     # pg_dump and pg_restore.
!     # So remove their sources from the object, keeping the other setup that
!     # AddSimpleFrontend() has done.
!     my @nodumpall = grep  { m/src\\bin\\pg_dump\\.*\.c$/ }
!       keys %{$pgdumpall->{files}};
      delete @{$pgdumpall->{files}}{@nodumpall};
      $pgdumpall->{name} = 'pg_dumpall';
      $pgdumpall->AddIncludeDir('src\backend');
*************** sub mkvcbuild
*** 508,513 ****
--- 512,518 ----
      $pgregress->AddReference($libpgport);
  
      $solution->Save();
+     return $solution->{vcver};
  }
  
  #####################
diff -Napcdr -x .git postgresql/src/tools/msvc/Project.pm postgresql_dev/src/tools/msvc/Project.pm
*** postgresql/src/tools/msvc/Project.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Project.pm	Mon Dec 26 20:14:30 2011
*************** use strict;
*** 10,18 ****
  use warnings;
  use File::Basename;
  
! sub new
  {
!     my ($junk, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
--- 10,18 ----
  use warnings;
  use File::Basename;
  
! sub _new
  {
!     my ($classname, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
*************** sub new
*** 20,43 ****
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name            => $name,
!         type            => $type,
!         guid            => Win32::GuidGen(),
!         files           => {},
!         references      => [],
!         libraries       => [],
!         suffixlib       => [],
!         includes        => '',
!         prefixincludes  => '',
!         defines         => ';',
!         solution        => $solution,
!         disablewarnings => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         vcver           => $solution->{vcver},
!         platform        => $solution->{platform},
      };
  
!     bless $self;
      return $self;
  }
  
--- 20,42 ----
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name                  => $name,
!         type                  => $type,
!         guid                  => Win32::GuidGen(),
!         files                 => {},
!         references            => [],
!         libraries             => [],
!         suffixlib             => [],
!         includes              => '',
!         prefixincludes        => '',
!         defines               => ';',
!         solution              => $solution,
!         disablewarnings       => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         platform              => $solution->{platform},
      };
  
!     bless($self, $classname);
      return $self;
  }
  
*************** sub Save
*** 355,489 ****
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}.vcproj") || croak("Could not write to $self->{name}.vcproj\n");
      $self->WriteHeader(*F);
!     $self->WriteReferences(*F);
!     print F <<EOF;
!  <Files>
! EOF
!     my @dirstack = ();
!     my %uniquefiles;
!     foreach my $f (sort keys %{ $self->{files} })
!     {
!         confess "Bad format filename '$f'\n" unless ($f =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
!         my $dir = $1;
!         my $file = $2;
! 
!         # Walk backwards down the directory stack and close any dirs we're done with
!         while ($#dirstack >= 0)
!         {
!             if (join('\\',@dirstack) eq substr($dir, 0, length(join('\\',@dirstack))))
!             {
!                 last if (length($dir) == length(join('\\',@dirstack)));
!                 last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
!             }
!             print F ' ' x $#dirstack . "  </Filter>\n";
!             pop @dirstack;
!         }
! 
!         # Now walk forwards and create whatever directories are needed
!         while (join('\\',@dirstack) ne $dir)
!         {
!             my $left = substr($dir, length(join('\\',@dirstack)));
!             $left =~ s/^\\//;
!             my @pieces = split /\\/, $left;
!             push @dirstack, $pieces[0];
!             print F ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
!         }
! 
!         print F ' ' x $#dirstack . "   <File RelativePath=\"$f\"";
!         if ($f =~ /\.y$/)
!         {
!             my $of = $f;
!             $of =~ s/\.y$/.c/;
!             $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print F '>'
!               . $self->GenerateCustomTool('Running bison on ' . $f,
!                 'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of)
!               . '</File>' . "\n";
!         }
!         elsif ($f =~ /\.l$/)
!         {
!             my $of = $f;
!             $of =~ s/\.l$/.c/;
!             print F '>'
!               . $self->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|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
!               . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
!               . "_$file.obj\" /></FileConfiguration></File>\n";
!         }
!         else
!         {
!             $uniquefiles{$file} = 1;
!             print F " />\n";
!         }
!     }
!     while ($#dirstack >= 0)
!     {
!         print F ' ' x $#dirstack . "  </Filter>\n";
!         pop @dirstack;
!     }
      $self->Footer(*F);
      close(F);
  }
  
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
! }
! 
! sub WriteHeader
! {
!     my ($self, $f) = @_;
! 
!     print $f <<EOF;
! <?xml version="1.0" encoding="Windows-1252"?>
! <VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}">
!  <Platforms><Platform Name="$self->{platform}"/></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 $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
--- 354,370 ----
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}$self->{filenameExtension}")
!       || croak("Could not write to $self->{name}$self->{filenameExtension}\n");
      $self->WriteHeader(*F);
!     $self->WriteFiles(*F);
      $self->Footer(*F);
      close(F);
  }
  
! sub GetAdditionalLinkerDependencies
  {
!     my ($self, $cfgname, $seperator) = @_;
      my $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
*************** sub WriteConfiguration
*** 497,572 ****
                  last;
              }
          }
!         $libs .= $xlib . " ";
      }
!     $libs =~ s/ $//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
! 
!     my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
! 
!     print $f <<EOF;
!   <Configuration Name="$cfgname|$self->{platform}" 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="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
! 		PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
! 		StringPooling="$p->{strpool}"
! 		RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
! 		AdditionalOptions="/MP"
! 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="$targetmachine"
! EOF
!     if ($self->{disablelinkerwarnings})
!     {
!         print $f "\t\tAdditionalOptions=\"/ignore:$self->{disablelinkerwarnings}\"\n";
!     }
!     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} $self->{platform}\" />\n";
!     }
!     print $f <<EOF;
!   </Configuration>
! EOF
! }
! 
! sub Footer
! {
!     my ($self, $f) = @_;
! 
!     print $f <<EOF;
!  </Files>
!  <Globals/>
! </VisualStudioProject>
! EOF
  }
  
  # Utility function that loads a complete file
--- 378,388 ----
                  last;
              }
          }
!         $libs .= $xlib . $seperator;
      }
!     $libs =~ s/.$//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
!     return $libs;
  }
  
  # Utility function that loads a complete file
diff -Napcdr -x .git postgresql/src/tools/msvc/README postgresql_dev/src/tools/msvc/README
*** postgresql/src/tools/msvc/README	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/README	Mon Dec 26 22:57:05 2011
*************** MSVC build
*** 4,22 ****
  ==========
  
  This directory contains the tools required to build PostgreSQL using
! Microsoft Visual Studio 2005. This builds the whole backend, not just
  the libpq frontend library. For more information, see the documentation
! chapter "Installation on Windows".
  
  
  Notes about Visual Studio Express
  ---------------------------------
! To build PostgreSQL using Visual Studio Express, the Platform SDK
  has to be installed. Since this is not included in the product
  originally, extra steps are needed to make it work.
  
! First, download and install the latest Platform SDK from
! www.microsoft.com.
  
  Locate the files vcprojectengine.dll.express.config and
  vcprojectengine.dll.config in the vc\vcpackages directory of
--- 4,22 ----
  ==========
  
  This directory contains the tools required to build PostgreSQL using
! Microsoft Visual Studio 2005 - 2011. This builds the whole backend, not just
  the libpq frontend library. For more information, see the documentation
! chapter "Installation on Windows" and the description below.
  
  
  Notes about Visual Studio Express
  ---------------------------------
! To build PostgreSQL using Visual Studio Express, the Microsoft Windows SDK
  has to be installed. Since this is not included in the product
  originally, extra steps are needed to make it work.
  
! First, download and install a supported version of the Microsoft Windows SDK
! from www.microsoft.com (v6.0 or greater).
  
  Locate the files vcprojectengine.dll.express.config and
  vcprojectengine.dll.config in the vc\vcpackages directory of
*************** to add them to the beginning of the list
*** 26,28 ****
--- 26,102 ----
  
  This should work for both GUI and commandline builds, but a restart
  may be necessary.
+ 
+ If you are using a recent version of the Microsoft Windows SDK that includes
+ the compilers and build tools you probably don't even need Visual Studio
+ Express to build PostgreSQL.
+ 
+ 
+ Structure of the build tools
+ ----------------------------
+ The tools for building PostgreSQL using Microsoft Visual Studio currently
+ consist of the following files:
+ 
+ - Configuration files -
+ config_default.pl      default configuration arguments
+ 
+ A typical build environment has two more files, buildenv.pl and config.pl
+ that contain the user's build environment settings and configuration
+ arguments.
+ 
+ 
+ - User tools -
+ build.pl               tool to build the binaries
+ builddoc.pl            tool to build the docs
+ clean.bat              batch file for cleaning up generated files
+ install.pl             tool to install the generated files
+ mkvcbuild.pl           tool to generate the Visual Studio build files
+ vcregress.pl           tool to run the regression tests
+ 
+ 
+ - Internal tools -
+ gendef.pl              internal tool to generate .DEF files
+ pgbison.pl             internal tool to process .y files using bison
+ pgflex.pl              internal tool to process .l files using flex
+ 
+ Many of those .pl files also have a corresponding .bat-wrapper that doesn't
+ contain any additional logic.
+ 
+ 
+ - Internal modules -
+ Install.pm             module containing the install logic
+ Mkvcbuild.pm           module containing the code to generate the Visual
+                        Studio build (project/solution) files
+ MSBuildProject.pm      module containing the code to generate MSBuild based
+                        project files (Visual Studio 2010 or greater)
+ Project.pm             module containing the common code to generate the
+                        Visual Studio project files. Also provides the
+                        common interface of all project file generators
+ Solution.pm            module containing the code to generate the Visual
+                        Studio solution files.
+ VCBuildProject.pm      module containing the code to generate VCBuild based
+                        project files (Visual Studio 2005/2008)
+ VSObjectFactory.pm     factory module providing the code to create the 
+                        appropriate project/solution files for the current
+                        environment
+ 
+ 
+ Description of the internals of the Visual Studio build process
+ ---------------------------------------------------------------
+ By typing 'build' the user starts the build.bat wrapper which simply passes
+ it's arguments to build.pl.
+ In build.pl the user's buildenv.pl is used to set up the build environment
+ (i. e. path to bison and flex). In addtion his config.pl file is merged into
+ config_default.pl to create the configuration arguments.
+ These configuration arguments are passed over to Mkvcbuild::mkvcbuild
+ (Mkvcbuild.pm) which creates the Visual Studio project and solution files.
+ It does this by using VSObjectFactory::CreateSolution to create an object
+ implementing the Solution interface (this could be either a VS2005Solution,
+ a VS2008Solution or a VS2010Solution, all in Solution.pm, depending on the
+ user's build environment) and adding objects implementing the corresponding
+ Project interface (VC2005Project or VC2008Project from VCBuildProject.pm or
+ VC2010Project from MSBuildProject.pm) to it.
+ When Solution::Save is called, the implementations of Solution and Project
+ save their content in the appropriate format.
+ The final step of starting the appropriate build program (msbuild or vcbuild)
+ is performed in build.pl again.
diff -Napcdr -x .git postgresql/src/tools/msvc/Solution.pm postgresql_dev/src/tools/msvc/Solution.pm
*** postgresql/src/tools/msvc/Solution.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Solution.pm	Mon Dec 26 20:14:31 2011
*************** package Solution;
*** 8,17 ****
  use Carp;
  use strict;
  use warnings;
  
! sub new
  {
!     my $junk = shift;
      my $options = shift;
      my $self = {
          projects => {},
--- 8,18 ----
  use Carp;
  use strict;
  use warnings;
+ use VSObjectFactory;
  
! sub _new
  {
!     my $classname = shift;
      my $options = shift;
      my $self = {
          projects => {},
*************** sub new
*** 21,27 ****
          vcver    => undef,
          platform => undef,
      };
!     bless $self;
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
--- 22,28 ----
          vcver    => undef,
          platform => undef,
      };
!     bless($self, $classname);
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
*************** sub new
*** 53,80 ****
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DetermineToolVersions();
  
      return $self;
  }
  
! sub DetermineToolVersions
  {
      my $self = shift;
  
-     # Determine version of vcbuild command, to set proper verison of visual studio
-     open(P,"vcbuild /? |") || die "vcbuild command not found";
-     my $line = <P>;
-     close(P);
-     if ($line !~ /^Microsoft\s*\(R\) Visual C\+\+ [^-]+ - \D+(\d+)\.00\.\d+/)
-     {
-         die "Unable to determine vcbuild version from first line of output!";
-     }
-     if ($1 == 8) { $self->{vcver} = '8.00' }
-     elsif ($1 == 9) { $self->{vcver} = '9.00' }
-     else { die "Unsupported version of Visual Studio: $1" }
-     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';
--- 54,68 ----
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DeterminePlatform();
  
      return $self;
  }
  
! sub DeterminePlatform
  {
      my $self = shift;
  
      # Determine if we are in 32 or 64-bit mode. Do this by seeing if CL has
      # 64-bit only parameters.
      $self->{platform} = 'Win32';
*************** sub AddProject
*** 428,434 ****
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = new Project($name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
--- 416,422 ----
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = VSObjectFactory::CreateProject($self->{vcver}, $name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
*************** sub Save
*** 488,495 ****
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version 9.00
! # Visual Studio 2005
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
--- 476,483 ----
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version $self->{solutionFileVersion}
! # $self->{visualStudioName}
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
*************** EOF
*** 497,503 ****
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}.vcproj", "$proj->{guid}"
  EndProject
  EOF
          }
--- 485,491 ----
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}$proj->{filenameExtension}", "$proj->{guid}"
  EndProject
  EOF
          }
*************** sub GetFakeConfigure
*** 577,582 ****
--- 565,640 ----
      $cfg .= ' --with-python' if ($self->{options}->{python});
  
      return $cfg;
+ }
+ 
+ package VS2005Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2005 solution file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '9.00';
+     $self->{vcver} = '8.00';
+     $self->{visualStudioName} = 'Visual Studio 2005';
+ 
+     return $self;
+ }
+ 
+ package VS2008Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2008 solution file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '10.00';
+     $self->{vcver} = '9.00';
+     $self->{visualStudioName} = 'Visual Studio 2008';
+ 
+     return $self;
+ }
+ 
+ package VS2010Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2010 solution file
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '11.00';
+     $self->{vcver} = '10.00';
+     $self->{visualStudioName} = 'Visual Studio 2010';
+ 
+     return $self;
  }
  
  1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VCBuildProject.pm postgresql_dev/src/tools/msvc/VCBuildProject.pm
*** postgresql/src/tools/msvc/VCBuildProject.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VCBuildProject.pm	Mon Dec 26 20:14:31 2011
***************
*** 0 ****
--- 1,267 ----
+ package VCBuildProject;
+ 
+ #
+ # Package that encapsulates a VCBuild (Visual C++ 2005/2008) project file
+ #
+ # src/tools/msvc/VCBuildProject.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub _new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{filenameExtension} = '.vcproj';
+ 
+     return $self;
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}">
+  <Platforms><Platform Name="$self->{platform}"/></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
+     $self->WriteReferences($f);
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+  <Files>
+ EOF
+     my @dirstack = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $file = $2;
+ 
+         # Walk backwards down the directory stack and close any dirs we're done with
+         while ($#dirstack >= 0)
+         {
+             if (join('\\',@dirstack) eq substr($dir, 0, length(join('\\',@dirstack))))
+             {
+                 last if (length($dir) == length(join('\\',@dirstack)));
+                 last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
+             }
+             print $f ' ' x $#dirstack . "  </Filter>\n";
+             pop @dirstack;
+         }
+ 
+         # Now walk forwards and create whatever directories are needed
+         while (join('\\',@dirstack) ne $dir)
+         {
+             my $left = substr($dir, length(join('\\',@dirstack)));
+             $left =~ s/^\\//;
+             my @pieces = split /\\/, $left;
+             push @dirstack, $pieces[0];
+             print $f ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
+         }
+ 
+         print $f ' ' x $#dirstack . "   <File RelativePath=\"$fileNameWithPath\"";
+         if ($fileNameWithPath =~ /\.y$/)
+         {
+             my $of = $fileNameWithPath;
+             $of =~ s/\.y$/.c/;
+             $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+             print $f '>'
+               . $self->GenerateCustomTool('Running bison on ' . $fileNameWithPath,
+                 "perl src\\tools\\msvc\\pgbison.pl $fileNameWithPath", $of)
+               . '</File>' . "\n";
+         }
+         elsif ($fileNameWithPath =~ /\.l$/)
+         {
+             my $of = $fileNameWithPath;
+             $of =~ s/\.l$/.c/;
+             print $f '>'
+               . $self->GenerateCustomTool('Running flex on ' . $fileNameWithPath,
+                 "perl src\\tools\\msvc\\pgflex.pl $fileNameWithPath", $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|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
+               . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
+               . "_$file.obj\" /></FileConfiguration></File>\n";
+         }
+         else
+         {
+             $uniquefiles{$file} = 1;
+             print $f " />\n";
+         }
+     }
+     while ($#dirstack >= 0)
+     {
+         print $f ' ' x $#dirstack . "  </Filter>\n";
+         pop @dirstack;
+     }
+     print $f <<EOF;
+  </Files>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+  <Globals/>
+ </VisualStudioProject>
+ EOF
+ }
+ 
+ sub WriteConfiguration
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ' ');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
+ 
+     print $f <<EOF;
+   <Configuration Name="$cfgname|$self->{platform}" 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="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
+ 		PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
+ 		StringPooling="$p->{strpool}"
+ 		RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
+ 		AdditionalOptions="/MP"
+ 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="$targetmachine"
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f "\t\tAdditionalOptions=\"/ignore:$self->{disablelinkerwarnings}\"\n";
+     }
+     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} $self->{platform}\" />\n";
+     }
+     print $f <<EOF;
+   </Configuration>
+ EOF
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+     print $f " <References>\n";
+     foreach my $ref (@{$self->{references}})
+     {
+         print $f
+ "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
+     }
+     print $f " </References>\n";
+ }
+ 
+ sub GenerateCustomTool
+ {
+     my ($self, $desc, $tool, $output, $cfg) = @_;
+     if (!defined($cfg))
+     {
+         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
+           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
+     }
+     return
+ "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
+ }
+ 
+ package VC2005Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2005 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(VCBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '8.00';
+ 
+     return $self;
+ }
+ 
+ package VC2008Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2008 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(VCBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '9.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VSObjectFactory.pm postgresql_dev/src/tools/msvc/VSObjectFactory.pm
*** postgresql/src/tools/msvc/VSObjectFactory.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VSObjectFactory.pm	Mon Dec 26 20:14:31 2011
***************
*** 0 ****
--- 1,122 ----
+ package VSObjectFactory;
+ 
+ #
+ # Package that creates Visual Studio wrapper objects for msvc build
+ #
+ # src/tools/msvc/VSObjectFactory.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ 
+ use Exporter;
+ use Project;
+ use Solution;
+ use VCBuildProject;
+ use MSBuildProject;
+ 
+ our (@ISA, @EXPORT);
+ @ISA = qw(Exporter);
+ @EXPORT = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
+ 
+ sub CreateSolution
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VS2005Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VS2008Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VS2010Solution(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub CreateProject
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VC2005Project(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VC2008Project(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VC2010Project(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub DetermineVisualStudioVersion
+ {
+     my $nmakeVersion = shift;
+ 
+     if (!defined($nmakeVersion))
+     {
+ 
+         # Determine version of nmake command, to set proper verison of visual studio
+         # we use nmake as it has existed for a long time and still exists in visual studio 2010
+         open(P,"nmake /? 2>&1 |")
+           || croak "Unable to determine Visual Studio version: The nmake command wasn't found.";
+         while(<P>)
+         {
+             chomp;
+             if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+             {
+                 return _GetVisualStudioVersion($1, $2);
+             }
+         }
+         close(P);
+     }
+     elsif($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+     {
+         return _GetVisualStudioVersion($1, $2);
+     }
+     croak "Unable to determine Visual Studio version: The nmake version could not be determined.";
+ }
+ 
+ sub _GetVisualStudioVersion
+ {
+     my($major, $minor) = @_;
+     if ($major > 10)
+     {
+         carp
+ "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
+         return '10.00';
+     }
+     elsif ($major < 6)
+     {
+         croak
+ "Unable to determine Visual Studio version: Visual Studio versions before 6.0 aren't supported.";
+     }
+     return "$major.$minor";
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/build.pl postgresql_dev/src/tools/msvc/build.pl
*** postgresql/src/tools/msvc/build.pl	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/build.pl	Mon Dec 26 20:14:29 2011
*************** our $config;
*** 33,39 ****
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
--- 33,39 ----
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! my $vcver = Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
*************** elsif ($ARGV[0] ne "RELEASE")
*** 50,56 ****
  
  # ... and do it
  
! if ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
--- 50,60 ----
  
  # ... and do it
  
! if ($buildwhat and $vcver eq '10.00')
! {
!     system("msbuild $buildwhat.vcxproj /verbosity:detailed /p:Configuration=$bconf");
! }
! elsif ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
diff -Napcdr -x .git postgresql/src/tools/msvc/builddoc.pl postgresql_dev/src/tools/msvc/builddoc.pl
*** postgresql/src/tools/msvc/builddoc.pl	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/builddoc.pl	Mon Dec 26 20:14:29 2011
*************** $cmd =
*** 69,76 ****
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
!   ."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
--- 69,76 ----
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd =
!   "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
diff -Napcdr -x .git postgresql/src/tools/msvc/clean.bat postgresql_dev/src/tools/msvc/clean.bat
*** postgresql/src/tools/msvc/clean.bat	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/clean.bat	Mon Dec 26 11:02:25 2011
*************** if exist ..\msvc if exist ..\..\..\src c
*** 10,17 ****
--- 10,21 ----
  if exist debug rd /s /q debug
  if exist release rd /s /q release
  for %%f in (*.vcproj) do del %%f
+ for %%f in (*.vcxproj) do del %%f
+ for %%f in (*.vcxproj.user) do del %%f
  if exist pgsql.sln del /q pgsql.sln
  if exist pgsql.sln.cache del /q pgsql.sln.cache
+ if exist pgsql.sdf del /q pgsql.sdf
+ if exist pgsql.suo del /q /a:H pgsql.suo
  del /s /q src\bin\win32ver.rc 2> NUL
  del /s /q src\interfaces\win32ver.rc 2> NUL
  if exist src\backend\win32ver.rc del /q src\backend\win32ver.rc
#30Brar Piening
brar@gmx.de
In reply to: Brar Piening (#29)
Re: Review of VS 2010 support patches

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual
Studio 2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that
breaks postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking
anythig else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

Regards,
Brar

#31Magnus Hagander
magnus@hagander.net
In reply to: Brar Piening (#30)
Re: Review of VS 2010 support patches

On Wed, Dec 28, 2011 at 05:09, Brar Piening <brar@gmx.de> wrote:

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual Studio
2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that breaks
postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking anythig
else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

What actual error do you get when trying to connect?

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#32Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#30)
Re: Review of VS 2010 support patches

On 12/27/2011 11:09 PM, Brar Piening wrote:

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails
during regression tests becuse it can't connect) when building with
Visual Studio 2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that
breaks postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking
anythig else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

Can you narrow down exactly what in that commit broke VS 2010? Are there
any compiler warnings?

cheers

andrew

#33Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#32)
Re: Review of VS 2010 support patches

On Wed, Dec 28, 2011 at 14:38, Andrew Dunstan <andrew@dunslane.net> wrote:

On 12/27/2011 11:09 PM, Brar Piening wrote:

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual Studio
2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that breaks
postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking anythig
else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

Can you narrow down exactly what in that commit broke VS 2010? Are there any
compiler warnings?

He did post the commit - 1a0c76c32fe470142d3663dd84ac960d75a4e8db.

Not the exact error or warnings, though ;)

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#34Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#33)
Re: Review of VS 2010 support patches

On 12/28/2011 08:43 AM, Magnus Hagander wrote:

On Wed, Dec 28, 2011 at 14:38, Andrew Dunstan<andrew@dunslane.net> wrote:

On 12/27/2011 11:09 PM, Brar Piening wrote:

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual Studio
2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that breaks
postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking anythig
else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

Can you narrow down exactly what in that commit broke VS 2010? Are there any
compiler warnings?

He did post the commit - 1a0c76c32fe470142d3663dd84ac960d75a4e8db.

I realize that. I'm asking him to narrow it down more.

cheers

andrew

#35Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#34)
Re: Review of VS 2010 support patches

On Wed, Dec 28, 2011 at 15:08, Andrew Dunstan <andrew@dunslane.net> wrote:

On 12/28/2011 08:43 AM, Magnus Hagander wrote:

On Wed, Dec 28, 2011 at 14:38, Andrew Dunstan<andrew@dunslane.net>  wrote:

On 12/27/2011 11:09 PM, Brar Piening wrote:

Brar Piening wrote:

I have to admit that it's currently broken (it builds but fails during
regression tests becuse it can't connect) when building with Visual
Studio
2010 or Windows SDK 7.1 because of commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db (Enable compiling with the
mingw-w64 32 bit compiler).

It seems like VS 2010 has a few of the E... constants in
src/include/port/win32.h already defined, but obviously in a way that
breaks
postgres.

Because of my missing experience and as I don't have a Mingw64 build
environment I don't feel like I could fix that without breaking anythig
else.

I'd like to add that I'm certainly willing to test suggested fixes or
patches in my VS 2010 build environment.

Can you narrow down exactly what in that commit broke VS 2010? Are there
any
compiler warnings?

He did post the commit - 1a0c76c32fe470142d3663dd84ac960d75a4e8db.

I realize that. I'm asking him to narrow it down more.

Meh. I can't read. Sorry about that.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#36Brar Piening
brar@gmx.de
In reply to: Andrew Dunstan (#32)
Re: Review of VS 2010 support patches

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010? Are
there any compiler warnings?

I was able to nail down the problem.

Running the regression tests (vcregress check) gives the following messages:
<snip>
============== creating temporary installation ==============
============== initializing database system ==============
============== starting postmaster ==============

pg_regress: postmaster did not respond within 60 seconds
Examine src/test/regress/log/postmaster.log for the reason
</snip>

postmaster.log shows the following messages:
<snip>
LOG: database system was shut down at 2011-12-28 22:09:46 CET
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: incomplete startup packet
</snip>
with the line "LOG: incomplete startup packet" repeated several times
afterwards.

The problem seems to be related to an invalid socket error constant.
EWOULDBLOCK gets expanded to 140 with commit
1a0c76c32fe470142d3663dd84ac960d75a4e8db applied whereas it got expanded
to 10035L before.
Adding the following code to src/include/port/win32.h restores the
former (running) behaviour :
<snip>
#if _MSC_VER >= 1600
#pragma warning(disable:4005)
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
</snip>

But according to the winsock docs this minimal invasive surgery isn't
really appropriate (at least for visual c).
http://msdn.microsoft.com/en-us/library/windows/desktop/ms737828(v=vs.85).aspx

It appears that VS 2010 and Windows SDK 7.1 now have an extended errno.h
that defines quite a few of the E* constants:
<snip>
/* POSIX SUPPLEMENT */
#define EADDRINUSE 100
#define EADDRNOTAVAIL 101
[...]
#define ETXTBSY 139
#define EWOULDBLOCK 140
</snip>

Here we probably run into the conflict that winsock2.h has always been
warning about:
<snip>
/*
* Windows Sockets errors redefined as regular Berkeley error constants.
* These are commented out in Windows NT to avoid conflicts with errno.h.
* Use the WSA constants instead.
*/
#if 0
#define EWOULDBLOCK WSAEWOULDBLOCK
[...]
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
#endif
</snip>

A possible solution would be to use something like PGEWOULDBLOCK and
similiar constants wherever socket errors are used and set them to the
WSAE* constants on windows and the E* constants on other platforms.

Anyhow, this would be ways beyond the scope of my patch and there will
probably be a better solution to be suggested from a real C hacker.

Regards,

Brar

#37Brar Piening
brar@gmx.de
In reply to: Brar Piening (#36)
1 attachment(s)
Re: Review of VS 2010 support patches

Brar Piening wrote:

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010? Are
there any compiler warnings?

I was able to nail down the problem.

In the absence of reaction, to keep my promise, I'm sending the attached
Patch which restores the previous working behaviour for Visual Studio 2011.
Note however that it also restores the previous conflicts with errno.h
which aren't neccessarily a problem, but might be in future.

Regards,

Brar

Attachments:

VS2010v12.patchtext/plain; name=VS2010v12.patchDownload
diff -Napcdr -x .git postgresql/doc/src/sgml/install-windows.sgml postgresql_dev/doc/src/sgml/install-windows.sgml
*** postgresql/doc/src/sgml/install-windows.sgml	Sun Dec 25 20:45:34 2011
--- postgresql_dev/doc/src/sgml/install-windows.sgml	Sat Dec 31 23:07:00 2011
***************
*** 20,29 ****
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Platform SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005 or 2008</productname>. In some cases
!   that requires the installation of the <productname>Platform SDK</productname>
    in addition to the compiler.
   </para>
  
--- 20,29 ----
    There are several different ways of building PostgreSQL on
    <productname>Windows</productname>. The simplest way to build with
    Microsoft tools is to install a supported version of the
!   <productname>Microsoft Windows SDK</productname> and use the included
    compiler. It is also possible to build with the full
!   <productname>Microsoft Visual C++ 2005, 2008 or 2010</productname>. In some cases
!   that requires the installation of the <productname>Windows SDK</productname>
    in addition to the compiler.
   </para>
  
***************
*** 69,100 ****
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Platform SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Platform SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way us to use the compilers in the <productname>Platform SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL supports the compilers from
!   <productname>Visual Studio 2005</productname> and
!   <productname>Visual Studio 2008</productname>. When using the Platform SDK
!   only, or when building for 64-bit Windows, only
!   <productname>Visual Studio 2008</productname> is supported.
!   <productname>Visual Studio 2010</productname> is not yet supported.
!  </para>
! 
!  <para>
!   When building using the <productname>Platform SDK</productname>, versions
!   6.0 to 7.0 of the SDK are supported. Older or newer versions will not work.
!   In particular, versions from 7.0a and later will not work, since
!   they include compilers from <productname>Visual Studio 2010</productname>.
   </para>
  
   <para>
--- 69,94 ----
  
   <sect1 id="install-windows-full">
    <title>Building with <productname>Visual C++</productname> or the
!   <productname>Microsoft Windows SDK</productname></title>
  
   <para>
    PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
    These compilers can be either from <productname>Visual Studio</productname>,
    <productname>Visual Studio Express</productname> or some versions of the
!   <productname>Microsoft Windows SDK</productname>. If you do not already have a
    <productname>Visual Studio</productname> environment set up, the easiest
!   way is to use the compilers in the <productname>Windows SDK</productname>,
    which is a free download from Microsoft.
   </para>
  
   <para>
!   PostgreSQL is known to support compilation using the compilers shipped with
!   <productname>Visual Studio 2005</productname> to
!   <productname>Visual Studio 2010</productname> (including Express editions),
!   as well as standalone Windows SDK releases 6.0 to 7.1.
!   64-bit PostgreSQL builds are only supported with
!   <productname>Microsoft Windows SDK</productname> version 6.0a and above or
!   <productname>Visual Studio 2008</productname> and above.
   </para>
  
   <para>
***************
*** 104,114 ****
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>. In the
!   <productname>Platform SDK</productname>, start the
!   <application>CMD shell</application> listed under the SDK on the Start Menu.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
--- 98,110 ----
    <productname>Cygwin</productname> present in your system PATH. Also, make
    sure you have all the required Visual C++ tools available in the PATH. In
    <productname>Visual Studio</productname>, start the
!   <application>Visual Studio Command Prompt</application>.
    If you wish to build a 64-bit version, you must use the 64-bit version of
    the command, and vice versa.
+   In the <productname>Microsoft Windows SDK</productname>, start the
+   <application>CMD shell</application> listed under the SDK on the Start Menu.
+   In recent SDK versions you can change the targeted CPU architecture by using
+   the <command>setenv</command> command.
    All commands should be run from the <filename>src\tools\msvc</filename>
    directory.
   </para>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 148,164 ****
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Platform SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Platform SDK</productname> (currently
!       version 7.0), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Platform SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
--- 144,160 ----
  
     <variablelist>
      <varlistentry>
!      <term><productname>Microsoft Windows SDK</productname></term>
       <listitem><para>
        It is recommended that you upgrade to the latest supported version
!       of the <productname>Microsoft Windows SDK</productname> (currently
!       version 7.1), available for download from
        <ulink url="http://www.microsoft.com/downloads/"></>.
       </para>
       <para>
        You must always include the
        <application>Windows Headers and Libraries</application> part of the SDK.
!       If you install the <productname>Windows SDK</productname>
        including the <application>Visual C++ Compilers</application>,
        you don't need <productname>Visual Studio</productname> to build.
       </para></listitem>
*************** $ENV{PATH}=$ENV{PATH} . ';c:\some\where\
*** 202,207 ****
--- 198,207 ----
        Bison can be downloaded from <ulink url="http://gnuwin32.sourceforge.net"></>.
        Flex can be downloaded from
        <ulink url="http://www.postgresql.org/ftp/misc/winflex/"></>.
+       If you are using <productname>msysGit</productname> for accessing the
+       PostgreSQL <productname>Git</productname> repository you probably already
+       have recent versions of bison and flex in your <productname>Git</productname>
+       binary directory.
       </para>
  
       <note>
*************** $ENV{DOCROOT}='c:\docbook';
*** 479,485 ****
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Platform SDK</productname> method is recommended.
   </para>
  
   <para>
--- 479,485 ----
    static library to link into an application. For normal use the
    <productname>MinGW</productname> or
    <productname>Visual Studio</productname> or
!   <productname>Windows SDK</productname> method is recommended.
   </para>
  
   <para>
diff -Napcdr -x .git postgresql/src/include/port/win32.h postgresql_dev/src/include/port/win32.h
*** postgresql/src/include/port/win32.h	Sun Dec 25 20:45:50 2011
--- postgresql_dev/src/include/port/win32.h	Sat Dec 31 23:07:30 2011
*************** typedef int pid_t;
*** 300,305 ****
--- 300,325 ----
  #endif
  
  /*
+  * For Microsoft Visual Studio 2010 and above we intentionally redefine
+  * the regular Berkeley error constants and set them to the WSA constants.
+  * Note that this will break if those constants are used for anything else
+  * than Windows Sockets errors.
+  */
+ #if _MSC_VER >= 1600
+ #pragma warning(disable:4005)
+ #define EMSGSIZE WSAEMSGSIZE
+ #define EAFNOSUPPORT WSAEAFNOSUPPORT
+ #define EWOULDBLOCK WSAEWOULDBLOCK
+ #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
+ #define ECONNRESET WSAECONNRESET
+ #define EINPROGRESS WSAEINPROGRESS
+ #define ENOBUFS WSAENOBUFS
+ #define ECONNREFUSED WSAECONNREFUSED
+ #define EOPNOTSUPP WSAEOPNOTSUPP
+ #pragma warning(default:4005)
+ #endif 
+ 
+ /*
   * Extended locale functions with gratuitous underscore prefixes.
   * (These APIs are nevertheless fully documented by Microsoft.)
   */
diff -Napcdr -x .git postgresql/src/tools/msvc/Install.pm postgresql_dev/src/tools/msvc/Install.pm
*** postgresql/src/tools/msvc/Install.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Install.pm	Sat Dec 31 23:07:00 2011
*************** sub Install
*** 56,66 ****
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories(
!         $target, 'bin', 'lib', 'share',
!         'share/timezonesets','share/extension', 'share/contrib','doc',
!         'doc/extension', 'doc/contrib','symbols', 'share/tsearch_data'
!     );
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
--- 56,63 ----
      my $majorver = DetermineMajorVersion();
      print "Installing version $majorver for $conf in $target\n";
  
!     EnsureDirectories($target, 'bin', 'lib', 'share','share/timezonesets','share/extension',
!         'share/contrib','doc','doc/extension', 'doc/contrib','symbols', 'share/tsearch_data');
  
      CopySolutionOutput($conf, $target);
      lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
*************** sub CopySolutionOutput
*** 186,191 ****
--- 183,195 ----
      my $rem = qr{Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"\) = "([^"]+)"};
  
      my $sln = read_file("pgsql.sln") || croak "Could not open pgsql.sln\n";
+ 
+     my $vcproj = 'vcproj';
+     if ($sln =~ /Microsoft Visual Studio Solution File, Format Version (\d+)\.\d+/ && $1 >= 11)
+     {
+         $vcproj = 'vcxproj';
+     }
+ 
      print "Copying build output files...";
      while ($sln =~ $rem)
      {
*************** sub CopySolutionOutput
*** 195,220 ****
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.vcproj") || croak "Could not open $pf.vcproj\n";
!         if ($proj !~ qr{ConfigurationType="([^"]+)"})
!         {
!             croak "Could not parse $pf.vcproj\n";
!         }
!         if ($1 == 1)
          {
!             $dir = "bin";
!             $ext = "exe";
          }
!         elsif ($1 == 2)
          {
!             $dir = "lib";
!             $ext = "dll";
          }
          else
          {
! 
!             # Static lib, such as libpgport, only used internally during build, don't install
!             next;
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
--- 199,246 ----
  
          $sln =~ s/$rem//;
  
!         my $proj = read_file("$pf.$vcproj") || croak "Could not open $pf.$vcproj\n";
!         if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
          {
!             if ($1 == 1)
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 == 2)
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
!         elsif ($vcproj eq 'vcxproj' && $proj =~ qr{<ConfigurationType>(\w+)</ConfigurationType>})
          {
!             if ($1 eq 'Application')
!             {
!                 $dir = "bin";
!                 $ext = "exe";
!             }
!             elsif ($1 eq 'DynamicLibrary')
!             {
!                 $dir = "lib";
!                 $ext = "dll";
!             }
!             else # 'StaticLibrary'
!             {
! 
!                 # Static lib, such as libpgport, only used internally during build, don't install
!                 next;
!             }
          }
          else
          {
!             croak "Could not parse $pf.$vcproj\n";
          }
          lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
            || croak "Could not copy $pf.$ext\n";
*************** sub CopyIncludeFiles
*** 470,477 ****
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/',
!         'gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
--- 496,502 ----
          $target . '/include/server/',
          'src/include/', 'pg_config.h', 'pg_config_os.h'
      );
!     CopyFiles('Grammar header', $target . '/include/server/parser/','src/backend/parser/','gram.h');
      CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
      my $D;
      opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
diff -Napcdr -x .git postgresql/src/tools/msvc/MSBuildProject.pm postgresql_dev/src/tools/msvc/MSBuildProject.pm
*** postgresql/src/tools/msvc/MSBuildProject.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/MSBuildProject.pm	Sat Dec 31 23:07:00 2011
***************
*** 0 ****
--- 1,388 ----
+ package MSBuildProject;
+ 
+ #
+ # Package that encapsulates a MSBuild (Visual C++ 2010) project file
+ #
+ # src/tools/msvc/MSBuildProject.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub _new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{filenameExtension} = '.vcxproj';
+ 
+     return $self;
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+   <ItemGroup Label="ProjectConfigurations">
+ EOF
+     $self->WriteConfigurationHeader($f, 'Debug');
+     $self->WriteConfigurationHeader($f, 'Release');
+     print $f <<EOF;
+   </ItemGroup>
+   <PropertyGroup Label="Globals">
+     <ProjectGuid>$self->{guid}</ProjectGuid>
+   </PropertyGroup>
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
+ EOF
+     $self->WriteConfigurationPropertyGroup($f, 'Release',{ wholeopt=>'false' });
+     $self->WriteConfigurationPropertyGroup($f, 'Debug',{ wholeopt=>'false' });
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.props" />
+   <ImportGroup Label="ExtensionSettings">
+   </ImportGroup>
+ EOF
+     $self->WritePropertySheetsPropertyGroup($f, 'Release');
+     $self->WritePropertySheetsPropertyGroup($f, 'Debug');
+     print $f <<EOF;
+   <PropertyGroup Label="UserMacros" />
+   <PropertyGroup>
+     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ EOF
+     $self->WriteAdditionalProperties($f, 'Debug');
+     $self->WriteAdditionalProperties($f, 'Release');
+     print $f <<EOF;
+   </PropertyGroup>
+ EOF
+     $self->WriteItemDefinitionGroup(
+         $f, 'Debug',
+         {
+             defs=>'_DEBUG;DEBUG=1;',
+             opt=>'Disabled',
+             strpool=>'false',
+             runtime=>'MultiThreadedDebugDLL'
+         }
+     );
+     $self->WriteItemDefinitionGroup($f, 'Release',
+         { defs=>'', opt=>'Full', strpool=>'true', runtime=>'MultiThreadedDLL' });
+ }
+ 
+ sub AddDefine
+ {
+     my ($self, $def) = @_;
+ 
+     $self->{defines} .= $def . ';';
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+ 
+     my @references = @{$self->{references}};
+ 
+     if (scalar(@references))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $ref (@references)
+         {
+             print $f <<EOF;
+     <ProjectReference Include="$ref->{name}$ref->{filenameExtension}">
+       <Project>$ref->{guid}</Project>
+     </ProjectReference>
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+   <ItemGroup>
+ EOF
+     my @grammarFiles = ();
+     my @resourceFiles = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $fileName = $2;
+         if ($fileNameWithPath =~ /\.y$/ or $fileNameWithPath =~ /\.l$/)
+         {
+             push @grammarFiles, $fileNameWithPath;
+         }
+         elsif ($fileNameWithPath =~ /\.rc$/)
+         {
+             push @resourceFiles, $fileNameWithPath;
+         }
+         elsif (defined($uniquefiles{$fileName}))
+         {
+ 
+             # File already exists, so fake a new name
+             my $obj = $dir;
+             $obj =~ s/\\/_/g;
+ 
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath">
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">.\\debug\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+       <ObjectFileName Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">.\\release\\$self->{name}\\${obj}_$fileName.obj</ObjectFileName>
+     </ClCompile>
+ EOF
+         }
+         else
+         {
+             $uniquefiles{$fileName} = 1;
+             print $f <<EOF;
+     <ClCompile Include="$fileNameWithPath" />
+ EOF
+         }
+ 
+     }
+     print $f <<EOF;
+   </ItemGroup>
+ EOF
+     if (scalar(@grammarFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $grammarFile (@grammarFiles)
+         {
+             (my $outputFile = $grammarFile) =~ s/\.(y|l)$/.c/;
+             if ($grammarFile =~ /\.y$/)
+             {
+                 $outputFile =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running bison on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgbison.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+             else #if ($grammarFile =~ /\.l$/)
+             {
+                 print $f <<EOF;
+     <CustomBuild Include="$grammarFile">
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Debug|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+       <Message Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">Running flex on $grammarFile</Message>
+       <Command Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">perl "src\\tools\\msvc\\pgflex.pl" "$grammarFile"</Command>
+       <AdditionalInputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">%(AdditionalInputs)</AdditionalInputs>
+       <Outputs Condition="'\$(Configuration)|\$(Platform)'=='Release|$self->{platform}'">$outputFile;%(Outputs)</Outputs>
+     </CustomBuild>
+ EOF
+             }
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+     if (scalar(@resourceFiles))
+     {
+         print $f <<EOF;
+   <ItemGroup>
+ EOF
+         foreach my $rcFile (@resourceFiles)
+         {
+             print $f <<EOF;
+     <ResourceCompile Include="$rcFile" />
+ EOF
+         }
+         print $f <<EOF;
+   </ItemGroup>
+ EOF
+     }
+ }
+ 
+ sub WriteConfigurationHeader
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <ProjectConfiguration Include="$cfgname|$self->{platform}">
+       <Configuration>$cfgname</Configuration>
+       <Platform>$self->{platform}</Platform>
+     </ProjectConfiguration>
+ EOF
+ }
+ 
+ sub WriteConfigurationPropertyGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+ 
+     print $f <<EOF;
+   <PropertyGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="Configuration">
+     <ConfigurationType>$cfgtype</ConfigurationType>
+     <UseOfMfc>false</UseOfMfc>
+     <CharacterSet>MultiByte</CharacterSet>
+     <WholeProgramOptimization>$p->{wholeopt}</WholeProgramOptimization>
+   </PropertyGroup>
+ EOF
+ }
+ 
+ sub WritePropertySheetsPropertyGroup
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+   <ImportGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'" Label="PropertySheets">
+     <Import Project="\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props" Condition="exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')" Label="LocalAppDataPlatform" />
+   </ImportGroup>
+ EOF
+ }
+ 
+ sub WriteAdditionalProperties
+ {
+     my ($self, $f, $cfgname) = @_;
+     print $f <<EOF;
+     <OutDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</OutDir>
+     <IntDir Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">.\\$cfgname\\$self->{name}\\</IntDir>
+     <LinkIncremental Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">false</LinkIncremental>
+ EOF
+ }
+ 
+ sub WriteItemDefinitionGroup
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype =
+       ($self->{type} eq "exe")
+       ?'Application'
+       :($self->{type} eq "dll"?'DynamicLibrary':'StaticLibrary');
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ';');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+ 
+     my $includes = $self->{includes};
+     unless ($includes eq '' or $includes =~ /;$/)
+     {
+         $includes .= ';';
+     }
+     print $f <<EOF;
+   <ItemDefinitionGroup Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">
+     <ClCompile>
+       <Optimization>$p->{opt}</Optimization>
+       <AdditionalIncludeDirectories>$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$includes\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+       <PreprocessorDefinitions>WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}\%(PreprocessorDefinitions)</PreprocessorDefinitions>
+       <StringPooling>$p->{strpool}</StringPooling>
+       <RuntimeLibrary>$p->{runtime}</RuntimeLibrary>
+       <DisableSpecificWarnings>$self->{disablewarnings};\%(DisableSpecificWarnings)</DisableSpecificWarnings>
+       <AdditionalOptions>/MP \%(AdditionalOptions)</AdditionalOptions>
+       <AssemblerOutput>
+       </AssemblerOutput>
+       <AssemblerListingLocation>.\\$cfgname\\$self->{name}\\</AssemblerListingLocation>
+       <ObjectFileName>.\\$cfgname\\$self->{name}\\</ObjectFileName>
+       <ProgramDataBaseFileName>.\\$cfgname\\$self->{name}\\</ProgramDataBaseFileName>
+       <BrowseInformation>false</BrowseInformation>
+       <WarningLevel>Level3</WarningLevel>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+       <CompileAs>Default</CompileAs>
+     </ClCompile>
+     <Link>
+       <OutputFile>.\\$cfgname\\$self->{name}\\$self->{name}.$self->{type}</OutputFile>
+       <AdditionalDependencies>$libs;\%(AdditionalDependencies)</AdditionalDependencies>
+       <SuppressStartupBanner>true</SuppressStartupBanner>
+       <AdditionalLibraryDirectories>\%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+       <IgnoreSpecificDefaultLibraries>libc;\%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+       <StackReserveSize>4194304</StackReserveSize>
+       <GenerateDebugInformation>true</GenerateDebugInformation>
+       <ProgramDatabaseFile>.\\$cfgname\\$self->{name}\\$self->{name}.pdb</ProgramDatabaseFile>
+       <GenerateMapFile>false</GenerateMapFile>
+       <MapFileName>.\\$cfgname\\$self->{name}\\$self->{name}.map</MapFileName>
+       <SubSystem>Console</SubSystem>
+       <TargetMachine>$targetmachine</TargetMachine>
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f
+ "      <AdditionalOptions>/ignore:$self->{disablelinkerwarnings} \%(AdditionalOptions)</AdditionalOptions>\n";
+     }
+     if ($self->{implib})
+     {
+         my $l = $self->{implib};
+         $l =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ImportLibrary>$l</ImportLibrary>\n";
+     }
+     if ($self->{def})
+     {
+         my $d = $self->{def};
+         $d =~ s/__CFGNAME__/$cfgname/g;
+         print $f "      <ModuleDefinitionFile>$d</ModuleDefinitionFile>\n";
+     }
+     print $f <<EOF;
+     </Link>
+     <ResourceCompile>
+       <AdditionalIncludeDirectories>src\\include;\%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+     </ResourceCompile>
+ EOF
+     if ($self->{builddef})
+     {
+         print $f <<EOF;
+     <PreLinkEvent>
+       <Message>Generate DEF file</Message>
+       <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+     </PreLinkEvent>
+ EOF
+     }
+     print $f <<EOF;
+   </ItemDefinitionGroup>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+     $self->WriteReferences($f);
+ 
+     print $f <<EOF;
+   <Import Project="\$(VCTargetsPath)\\Microsoft.Cpp.targets" />
+   <ImportGroup Label="ExtensionTargets">
+   </ImportGroup>
+ </Project>
+ EOF
+ }
+ 
+ package VC2010Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2010 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(MSBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '10.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/Mkvcbuild.pm postgresql_dev/src/tools/msvc/Mkvcbuild.pm
*** postgresql/src/tools/msvc/Mkvcbuild.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Mkvcbuild.pm	Sat Dec 31 23:07:00 2011
*************** use Solution;
*** 14,19 ****
--- 14,20 ----
  use Cwd;
  use File::Copy;
  use Config;
+ use VSObjectFactory;
  use List::Util qw(first);
  
  use Exporter;
*************** sub mkvcbuild
*** 47,53 ****
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     $solution = new Solution($config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
--- 48,56 ----
      chdir('..\..\..') if (-d '..\msvc' && -d '..\..\..\src');
      die 'Must run from root or msvc directory' unless (-d 'src\tools\msvc' && -d 'src');
  
!     my $vsVersion = DetermineVisualStudioVersion();
! 
!     $solution = CreateSolution($vsVersion, $config);
  
      our @pgportfiles = qw(
        chklocale.c crypt.c fseeko.c getrusage.c inet_aton.c random.c srandom.c
*************** sub mkvcbuild
*** 344,355 ****
      $pgdump->AddFile('src\backend\parser\kwlookup.c');
  
      my $pgdumpall = AddSimpleFrontend('pg_dump', 1);
! 	# pg_dumpall doesn't use the files in the Makefile's $(OBJS), unlike
! 	# pg_dump and pg_restore.
! 	# So remove their sources from the object, keeping the other setup that 
! 	# AddSimpleFrontend() has done.
!     my @nodumpall = grep  { m/src\\bin\\pg_dump\\.*\.c$/ } 
! 	keys %{$pgdumpall->{files}};
      delete @{$pgdumpall->{files}}{@nodumpall};
      $pgdumpall->{name} = 'pg_dumpall';
      $pgdumpall->AddIncludeDir('src\backend');
--- 347,359 ----
      $pgdump->AddFile('src\backend\parser\kwlookup.c');
  
      my $pgdumpall = AddSimpleFrontend('pg_dump', 1);
! 
!     # pg_dumpall doesn't use the files in the Makefile's $(OBJS), unlike
!     # pg_dump and pg_restore.
!     # So remove their sources from the object, keeping the other setup that
!     # AddSimpleFrontend() has done.
!     my @nodumpall = grep  { m/src\\bin\\pg_dump\\.*\.c$/ }
!       keys %{$pgdumpall->{files}};
      delete @{$pgdumpall->{files}}{@nodumpall};
      $pgdumpall->{name} = 'pg_dumpall';
      $pgdumpall->AddIncludeDir('src\backend');
*************** sub mkvcbuild
*** 508,513 ****
--- 512,518 ----
      $pgregress->AddReference($libpgport);
  
      $solution->Save();
+     return $solution->{vcver};
  }
  
  #####################
diff -Napcdr -x .git postgresql/src/tools/msvc/Project.pm postgresql_dev/src/tools/msvc/Project.pm
*** postgresql/src/tools/msvc/Project.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Project.pm	Sat Dec 31 23:07:00 2011
*************** use strict;
*** 10,18 ****
  use warnings;
  use File::Basename;
  
! sub new
  {
!     my ($junk, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
--- 10,18 ----
  use warnings;
  use File::Basename;
  
! sub _new
  {
!     my ($classname, $name, $type, $solution) = @_;
      my $good_types = {
          lib => 1,
          exe => 1,
*************** sub new
*** 20,43 ****
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name            => $name,
!         type            => $type,
!         guid            => Win32::GuidGen(),
!         files           => {},
!         references      => [],
!         libraries       => [],
!         suffixlib       => [],
!         includes        => '',
!         prefixincludes  => '',
!         defines         => ';',
!         solution        => $solution,
!         disablewarnings => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         vcver           => $solution->{vcver},
!         platform        => $solution->{platform},
      };
  
!     bless $self;
      return $self;
  }
  
--- 20,42 ----
      };
      confess("Bad project type: $type\n") unless exists $good_types->{$type};
      my $self = {
!         name                  => $name,
!         type                  => $type,
!         guid                  => Win32::GuidGen(),
!         files                 => {},
!         references            => [],
!         libraries             => [],
!         suffixlib             => [],
!         includes              => '',
!         prefixincludes        => '',
!         defines               => ';',
!         solution              => $solution,
!         disablewarnings       => '4018;4244;4273;4102;4090;4267',
          disablelinkerwarnings => '',
!         platform              => $solution->{platform},
      };
  
!     bless($self, $classname);
      return $self;
  }
  
*************** sub Save
*** 355,489 ****
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}.vcproj") || croak("Could not write to $self->{name}.vcproj\n");
      $self->WriteHeader(*F);
!     $self->WriteReferences(*F);
!     print F <<EOF;
!  <Files>
! EOF
!     my @dirstack = ();
!     my %uniquefiles;
!     foreach my $f (sort keys %{ $self->{files} })
!     {
!         confess "Bad format filename '$f'\n" unless ($f =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
!         my $dir = $1;
!         my $file = $2;
! 
!         # Walk backwards down the directory stack and close any dirs we're done with
!         while ($#dirstack >= 0)
!         {
!             if (join('\\',@dirstack) eq substr($dir, 0, length(join('\\',@dirstack))))
!             {
!                 last if (length($dir) == length(join('\\',@dirstack)));
!                 last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
!             }
!             print F ' ' x $#dirstack . "  </Filter>\n";
!             pop @dirstack;
!         }
! 
!         # Now walk forwards and create whatever directories are needed
!         while (join('\\',@dirstack) ne $dir)
!         {
!             my $left = substr($dir, length(join('\\',@dirstack)));
!             $left =~ s/^\\//;
!             my @pieces = split /\\/, $left;
!             push @dirstack, $pieces[0];
!             print F ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
!         }
! 
!         print F ' ' x $#dirstack . "   <File RelativePath=\"$f\"";
!         if ($f =~ /\.y$/)
!         {
!             my $of = $f;
!             $of =~ s/\.y$/.c/;
!             $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
!             print F '>'
!               . $self->GenerateCustomTool('Running bison on ' . $f,
!                 'cmd /V:ON /c src\tools\msvc\pgbison.bat ' . $f, $of)
!               . '</File>' . "\n";
!         }
!         elsif ($f =~ /\.l$/)
!         {
!             my $of = $f;
!             $of =~ s/\.l$/.c/;
!             print F '>'
!               . $self->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|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
!               . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
!               . "_$file.obj\" /></FileConfiguration></File>\n";
!         }
!         else
!         {
!             $uniquefiles{$file} = 1;
!             print F " />\n";
!         }
!     }
!     while ($#dirstack >= 0)
!     {
!         print F ' ' x $#dirstack . "  </Filter>\n";
!         pop @dirstack;
!     }
      $self->Footer(*F);
      close(F);
  }
  
! sub GenerateCustomTool
! {
!     my ($self, $desc, $tool, $output, $cfg) = @_;
!     if (!defined($cfg))
!     {
!         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
!           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
!     }
!     return
! "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
! }
! 
! sub WriteReferences
! {
!     my ($self, $f) = @_;
!     print $f " <References>\n";
!     foreach my $ref (@{$self->{references}})
!     {
!         print $f
! "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
!     }
!     print $f " </References>\n";
! }
! 
! sub WriteHeader
! {
!     my ($self, $f) = @_;
! 
!     print $f <<EOF;
! <?xml version="1.0" encoding="Windows-1252"?>
! <VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}">
!  <Platforms><Platform Name="$self->{platform}"/></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 $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
--- 354,370 ----
      $self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
  
      # Dump the project
!     open(F, ">$self->{name}$self->{filenameExtension}")
!       || croak("Could not write to $self->{name}$self->{filenameExtension}\n");
      $self->WriteHeader(*F);
!     $self->WriteFiles(*F);
      $self->Footer(*F);
      close(F);
  }
  
! sub GetAdditionalLinkerDependencies
  {
!     my ($self, $cfgname, $seperator) = @_;
      my $libcfg = (uc $cfgname eq "RELEASE")?"MD":"MDd";
      my $libs = '';
      foreach my $lib (@{$self->{libraries}})
*************** sub WriteConfiguration
*** 497,572 ****
                  last;
              }
          }
!         $libs .= $xlib . " ";
      }
!     $libs =~ s/ $//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
! 
!     my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
! 
!     print $f <<EOF;
!   <Configuration Name="$cfgname|$self->{platform}" 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="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
! 		PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
! 		StringPooling="$p->{strpool}"
! 		RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
! 		AdditionalOptions="/MP"
! 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="$targetmachine"
! EOF
!     if ($self->{disablelinkerwarnings})
!     {
!         print $f "\t\tAdditionalOptions=\"/ignore:$self->{disablelinkerwarnings}\"\n";
!     }
!     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} $self->{platform}\" />\n";
!     }
!     print $f <<EOF;
!   </Configuration>
! EOF
! }
! 
! sub Footer
! {
!     my ($self, $f) = @_;
! 
!     print $f <<EOF;
!  </Files>
!  <Globals/>
! </VisualStudioProject>
! EOF
  }
  
  # Utility function that loads a complete file
--- 378,388 ----
                  last;
              }
          }
!         $libs .= $xlib . $seperator;
      }
!     $libs =~ s/.$//;
      $libs =~ s/__CFGNAME__/$cfgname/g;
!     return $libs;
  }
  
  # Utility function that loads a complete file
diff -Napcdr -x .git postgresql/src/tools/msvc/README postgresql_dev/src/tools/msvc/README
*** postgresql/src/tools/msvc/README	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/README	Sat Dec 31 23:07:00 2011
*************** MSVC build
*** 4,22 ****
  ==========
  
  This directory contains the tools required to build PostgreSQL using
! Microsoft Visual Studio 2005. This builds the whole backend, not just
  the libpq frontend library. For more information, see the documentation
! chapter "Installation on Windows".
  
  
  Notes about Visual Studio Express
  ---------------------------------
! To build PostgreSQL using Visual Studio Express, the Platform SDK
  has to be installed. Since this is not included in the product
  originally, extra steps are needed to make it work.
  
! First, download and install the latest Platform SDK from
! www.microsoft.com.
  
  Locate the files vcprojectengine.dll.express.config and
  vcprojectengine.dll.config in the vc\vcpackages directory of
--- 4,22 ----
  ==========
  
  This directory contains the tools required to build PostgreSQL using
! Microsoft Visual Studio 2005 - 2011. This builds the whole backend, not just
  the libpq frontend library. For more information, see the documentation
! chapter "Installation on Windows" and the description below.
  
  
  Notes about Visual Studio Express
  ---------------------------------
! To build PostgreSQL using Visual Studio Express, the Microsoft Windows SDK
  has to be installed. Since this is not included in the product
  originally, extra steps are needed to make it work.
  
! First, download and install a supported version of the Microsoft Windows SDK
! from www.microsoft.com (v6.0 or greater).
  
  Locate the files vcprojectengine.dll.express.config and
  vcprojectengine.dll.config in the vc\vcpackages directory of
*************** to add them to the beginning of the list
*** 26,28 ****
--- 26,102 ----
  
  This should work for both GUI and commandline builds, but a restart
  may be necessary.
+ 
+ If you are using a recent version of the Microsoft Windows SDK that includes
+ the compilers and build tools you probably don't even need Visual Studio
+ Express to build PostgreSQL.
+ 
+ 
+ Structure of the build tools
+ ----------------------------
+ The tools for building PostgreSQL using Microsoft Visual Studio currently
+ consist of the following files:
+ 
+ - Configuration files -
+ config_default.pl      default configuration arguments
+ 
+ A typical build environment has two more files, buildenv.pl and config.pl
+ that contain the user's build environment settings and configuration
+ arguments.
+ 
+ 
+ - User tools -
+ build.pl               tool to build the binaries
+ builddoc.pl            tool to build the docs
+ clean.bat              batch file for cleaning up generated files
+ install.pl             tool to install the generated files
+ mkvcbuild.pl           tool to generate the Visual Studio build files
+ vcregress.pl           tool to run the regression tests
+ 
+ 
+ - Internal tools -
+ gendef.pl              internal tool to generate .DEF files
+ pgbison.pl             internal tool to process .y files using bison
+ pgflex.pl              internal tool to process .l files using flex
+ 
+ Many of those .pl files also have a corresponding .bat-wrapper that doesn't
+ contain any additional logic.
+ 
+ 
+ - Internal modules -
+ Install.pm             module containing the install logic
+ Mkvcbuild.pm           module containing the code to generate the Visual
+                        Studio build (project/solution) files
+ MSBuildProject.pm      module containing the code to generate MSBuild based
+                        project files (Visual Studio 2010 or greater)
+ Project.pm             module containing the common code to generate the
+                        Visual Studio project files. Also provides the
+                        common interface of all project file generators
+ Solution.pm            module containing the code to generate the Visual
+                        Studio solution files.
+ VCBuildProject.pm      module containing the code to generate VCBuild based
+                        project files (Visual Studio 2005/2008)
+ VSObjectFactory.pm     factory module providing the code to create the 
+                        appropriate project/solution files for the current
+                        environment
+ 
+ 
+ Description of the internals of the Visual Studio build process
+ ---------------------------------------------------------------
+ By typing 'build' the user starts the build.bat wrapper which simply passes
+ it's arguments to build.pl.
+ In build.pl the user's buildenv.pl is used to set up the build environment
+ (i. e. path to bison and flex). In addtion his config.pl file is merged into
+ config_default.pl to create the configuration arguments.
+ These configuration arguments are passed over to Mkvcbuild::mkvcbuild
+ (Mkvcbuild.pm) which creates the Visual Studio project and solution files.
+ It does this by using VSObjectFactory::CreateSolution to create an object
+ implementing the Solution interface (this could be either a VS2005Solution,
+ a VS2008Solution or a VS2010Solution, all in Solution.pm, depending on the
+ user's build environment) and adding objects implementing the corresponding
+ Project interface (VC2005Project or VC2008Project from VCBuildProject.pm or
+ VC2010Project from MSBuildProject.pm) to it.
+ When Solution::Save is called, the implementations of Solution and Project
+ save their content in the appropriate format.
+ The final step of starting the appropriate build program (msbuild or vcbuild)
+ is performed in build.pl again.
diff -Napcdr -x .git postgresql/src/tools/msvc/Solution.pm postgresql_dev/src/tools/msvc/Solution.pm
*** postgresql/src/tools/msvc/Solution.pm	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/Solution.pm	Sat Dec 31 23:07:00 2011
*************** package Solution;
*** 8,17 ****
  use Carp;
  use strict;
  use warnings;
  
! sub new
  {
!     my $junk = shift;
      my $options = shift;
      my $self = {
          projects => {},
--- 8,18 ----
  use Carp;
  use strict;
  use warnings;
+ use VSObjectFactory;
  
! sub _new
  {
!     my $classname = shift;
      my $options = shift;
      my $self = {
          projects => {},
*************** sub new
*** 21,27 ****
          vcver    => undef,
          platform => undef,
      };
!     bless $self;
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
--- 22,28 ----
          vcver    => undef,
          platform => undef,
      };
!     bless($self, $classname);
  
      # integer_datetimes is now the default
      $options->{integer_datetimes} = 1
*************** sub new
*** 53,80 ****
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DetermineToolVersions();
  
      return $self;
  }
  
! sub DetermineToolVersions
  {
      my $self = shift;
  
-     # Determine version of vcbuild command, to set proper verison of visual studio
-     open(P,"vcbuild /? |") || die "vcbuild command not found";
-     my $line = <P>;
-     close(P);
-     if ($line !~ /^Microsoft\s*\(R\) Visual C\+\+ [^-]+ - \D+(\d+)\.00\.\d+/)
-     {
-         die "Unable to determine vcbuild version from first line of output!";
-     }
-     if ($1 == 8) { $self->{vcver} = '8.00' }
-     elsif ($1 == 9) { $self->{vcver} = '9.00' }
-     else { die "Unsupported version of Visual Studio: $1" }
-     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';
--- 54,68 ----
      die "Bad wal_segsize $options->{wal_segsize}"
        unless grep {$_ == $options->{wal_segsize}} (1,2,4,8,16,32,64);
  
!     $self->DeterminePlatform();
  
      return $self;
  }
  
! sub DeterminePlatform
  {
      my $self = shift;
  
      # Determine if we are in 32 or 64-bit mode. Do this by seeing if CL has
      # 64-bit only parameters.
      $self->{platform} = 'Win32';
*************** sub AddProject
*** 428,434 ****
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = new Project($name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
--- 416,422 ----
  {
      my ($self, $name, $type, $folder, $initialdir) = @_;
  
!     my $proj = VSObjectFactory::CreateProject($self->{vcver}, $name, $type, $self);
      push @{$self->{projects}->{$folder}}, $proj;
      $proj->AddDir($initialdir) if ($initialdir);
      if ($self->{options}->{zlib})
*************** sub Save
*** 488,495 ****
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version 9.00
! # Visual Studio 2005
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
--- 476,483 ----
  
      open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
      print SLN <<EOF;
! Microsoft Visual Studio Solution File, Format Version $self->{solutionFileVersion}
! # $self->{visualStudioName}
  EOF
  
      foreach my $fld (keys %{$self->{projects}})
*************** EOF
*** 497,503 ****
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}.vcproj", "$proj->{guid}"
  EndProject
  EOF
          }
--- 485,491 ----
          foreach my $proj (@{$self->{projects}->{$fld}})
          {
              print SLN <<EOF;
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}$proj->{filenameExtension}", "$proj->{guid}"
  EndProject
  EOF
          }
*************** sub GetFakeConfigure
*** 577,582 ****
--- 565,640 ----
      $cfg .= ' --with-python' if ($self->{options}->{python});
  
      return $cfg;
+ }
+ 
+ package VS2005Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2005 solution file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '9.00';
+     $self->{vcver} = '8.00';
+     $self->{visualStudioName} = 'Visual Studio 2005';
+ 
+     return $self;
+ }
+ 
+ package VS2008Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2008 solution file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '10.00';
+     $self->{vcver} = '9.00';
+     $self->{visualStudioName} = 'Visual Studio 2008';
+ 
+     return $self;
+ }
+ 
+ package VS2010Solution;
+ 
+ #
+ # Package that encapsulates a Visual Studio 2010 solution file
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Solution);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{solutionFileVersion} = '11.00';
+     $self->{vcver} = '10.00';
+     $self->{visualStudioName} = 'Visual Studio 2010';
+ 
+     return $self;
  }
  
  1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VCBuildProject.pm postgresql_dev/src/tools/msvc/VCBuildProject.pm
*** postgresql/src/tools/msvc/VCBuildProject.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VCBuildProject.pm	Sat Dec 31 23:07:00 2011
***************
*** 0 ****
--- 1,267 ----
+ package VCBuildProject;
+ 
+ #
+ # Package that encapsulates a VCBuild (Visual C++ 2005/2008) project file
+ #
+ # src/tools/msvc/VCBuildProject.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ use base qw(Project);
+ 
+ sub _new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{filenameExtension} = '.vcproj';
+ 
+     return $self;
+ }
+ 
+ sub WriteHeader
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+ <?xml version="1.0" encoding="Windows-1252"?>
+ <VisualStudioProject ProjectType="Visual C++" Version="$self->{vcver}" Name="$self->{name}" ProjectGUID="$self->{guid}">
+  <Platforms><Platform Name="$self->{platform}"/></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
+     $self->WriteReferences($f);
+ }
+ 
+ sub WriteFiles
+ {
+     my ($self, $f) = @_;
+     print $f <<EOF;
+  <Files>
+ EOF
+     my @dirstack = ();
+     my %uniquefiles;
+     foreach my $fileNameWithPath (sort keys %{ $self->{files} })
+     {
+         confess "Bad format filename '$fileNameWithPath'\n"
+           unless ($fileNameWithPath =~ /^(.*)\\([^\\]+)\.[r]?[cyl]$/);
+         my $dir = $1;
+         my $file = $2;
+ 
+         # Walk backwards down the directory stack and close any dirs we're done with
+         while ($#dirstack >= 0)
+         {
+             if (join('\\',@dirstack) eq substr($dir, 0, length(join('\\',@dirstack))))
+             {
+                 last if (length($dir) == length(join('\\',@dirstack)));
+                 last if (substr($dir, length(join('\\',@dirstack)),1) eq '\\');
+             }
+             print $f ' ' x $#dirstack . "  </Filter>\n";
+             pop @dirstack;
+         }
+ 
+         # Now walk forwards and create whatever directories are needed
+         while (join('\\',@dirstack) ne $dir)
+         {
+             my $left = substr($dir, length(join('\\',@dirstack)));
+             $left =~ s/^\\//;
+             my @pieces = split /\\/, $left;
+             push @dirstack, $pieces[0];
+             print $f ' ' x $#dirstack . "  <Filter Name=\"$pieces[0]\" Filter=\"\">\n";
+         }
+ 
+         print $f ' ' x $#dirstack . "   <File RelativePath=\"$fileNameWithPath\"";
+         if ($fileNameWithPath =~ /\.y$/)
+         {
+             my $of = $fileNameWithPath;
+             $of =~ s/\.y$/.c/;
+             $of =~ s{^src\\pl\\plpgsql\\src\\gram.c$}{src\\pl\\plpgsql\\src\\pl_gram.c};
+             print $f '>'
+               . $self->GenerateCustomTool('Running bison on ' . $fileNameWithPath,
+                 "perl src\\tools\\msvc\\pgbison.pl $fileNameWithPath", $of)
+               . '</File>' . "\n";
+         }
+         elsif ($fileNameWithPath =~ /\.l$/)
+         {
+             my $of = $fileNameWithPath;
+             $of =~ s/\.l$/.c/;
+             print $f '>'
+               . $self->GenerateCustomTool('Running flex on ' . $fileNameWithPath,
+                 "perl src\\tools\\msvc\\pgflex.pl $fileNameWithPath", $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|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\debug\\$self->{name}\\$obj"
+               . "_$file.obj\" /></FileConfiguration><FileConfiguration Name=\"Release|$self->{platform}\"><Tool Name=\"VCCLCompilerTool\" ObjectFile=\".\\release\\$self->{name}\\$obj"
+               . "_$file.obj\" /></FileConfiguration></File>\n";
+         }
+         else
+         {
+             $uniquefiles{$file} = 1;
+             print $f " />\n";
+         }
+     }
+     while ($#dirstack >= 0)
+     {
+         print $f ' ' x $#dirstack . "  </Filter>\n";
+         pop @dirstack;
+     }
+     print $f <<EOF;
+  </Files>
+ EOF
+ }
+ 
+ sub Footer
+ {
+     my ($self, $f) = @_;
+ 
+     print $f <<EOF;
+  <Globals/>
+ </VisualStudioProject>
+ EOF
+ }
+ 
+ sub WriteConfiguration
+ {
+     my ($self, $f, $cfgname, $p) = @_;
+     my $cfgtype = ($self->{type} eq "exe")?1:($self->{type} eq "dll"?2:4);
+     my $libs = $self->GetAdditionalLinkerDependencies($cfgname, ' ');
+ 
+     my $targetmachine = $self->{platform} eq 'Win32' ? 1 : 17;
+ 
+     print $f <<EOF;
+   <Configuration Name="$cfgname|$self->{platform}" 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="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
+ 		PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
+ 		StringPooling="$p->{strpool}"
+ 		RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
+ 		AdditionalOptions="/MP"
+ 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="$targetmachine"
+ EOF
+     if ($self->{disablelinkerwarnings})
+     {
+         print $f "\t\tAdditionalOptions=\"/ignore:$self->{disablelinkerwarnings}\"\n";
+     }
+     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} $self->{platform}\" />\n";
+     }
+     print $f <<EOF;
+   </Configuration>
+ EOF
+ }
+ 
+ sub WriteReferences
+ {
+     my ($self, $f) = @_;
+     print $f " <References>\n";
+     foreach my $ref (@{$self->{references}})
+     {
+         print $f
+ "  <ProjectReference ReferencedProjectIdentifier=\"$ref->{guid}\" Name=\"$ref->{name}\" />\n";
+     }
+     print $f " </References>\n";
+ }
+ 
+ sub GenerateCustomTool
+ {
+     my ($self, $desc, $tool, $output, $cfg) = @_;
+     if (!defined($cfg))
+     {
+         return $self->GenerateCustomTool($desc, $tool, $output, 'Debug')
+           .$self->GenerateCustomTool($desc, $tool, $output, 'Release');
+     }
+     return
+ "<FileConfiguration Name=\"$cfg|$self->{platform}\"><Tool Name=\"VCCustomBuildTool\" Description=\"$desc\" CommandLine=\"$tool\" AdditionalDependencies=\"\" Outputs=\"$output\" /></FileConfiguration>";
+ }
+ 
+ package VC2005Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2005 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(VCBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '8.00';
+ 
+     return $self;
+ }
+ 
+ package VC2008Project;
+ 
+ #
+ # Package that encapsulates a Visual C++ 2008 project file
+ #
+ 
+ use strict;
+ use warnings;
+ use base qw(VCBuildProject);
+ 
+ sub new
+ {
+     my $classname = shift;
+     my $self = $classname->SUPER::_new(@_);
+     bless($self, $classname);
+ 
+     $self->{vcver} = '9.00';
+ 
+     return $self;
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/VSObjectFactory.pm postgresql_dev/src/tools/msvc/VSObjectFactory.pm
*** postgresql/src/tools/msvc/VSObjectFactory.pm	Thu Jan  1 00:00:00 1970
--- postgresql_dev/src/tools/msvc/VSObjectFactory.pm	Sat Dec 31 23:07:00 2011
***************
*** 0 ****
--- 1,122 ----
+ package VSObjectFactory;
+ 
+ #
+ # Package that creates Visual Studio wrapper objects for msvc build
+ #
+ # src/tools/msvc/VSObjectFactory.pm
+ #
+ 
+ use Carp;
+ use strict;
+ use warnings;
+ 
+ use Exporter;
+ use Project;
+ use Solution;
+ use VCBuildProject;
+ use MSBuildProject;
+ 
+ our (@ISA, @EXPORT);
+ @ISA = qw(Exporter);
+ @EXPORT = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
+ 
+ sub CreateSolution
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VS2005Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VS2008Solution(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VS2010Solution(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub CreateProject
+ {
+     my $visualStudioVersion = shift;
+ 
+     if (!defined($visualStudioVersion))
+     {
+         $visualStudioVersion = DetermineVisualStudioVersion();
+     }
+ 
+     if ($visualStudioVersion eq '8.00')
+     {
+         return new VC2005Project(@_);
+     }
+     elsif ($visualStudioVersion eq '9.00')
+     {
+         return new VC2008Project(@_);
+     }
+     elsif ($visualStudioVersion eq '10.00')
+     {
+         return new VC2010Project(@_);
+     }
+     else
+     {
+         croak "The requested Visual Studio version is not supported.";
+     }
+ }
+ 
+ sub DetermineVisualStudioVersion
+ {
+     my $nmakeVersion = shift;
+ 
+     if (!defined($nmakeVersion))
+     {
+ 
+         # Determine version of nmake command, to set proper verison of visual studio
+         # we use nmake as it has existed for a long time and still exists in visual studio 2010
+         open(P,"nmake /? 2>&1 |")
+           || croak "Unable to determine Visual Studio version: The nmake command wasn't found.";
+         while(<P>)
+         {
+             chomp;
+             if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+             {
+                 return _GetVisualStudioVersion($1, $2);
+             }
+         }
+         close(P);
+     }
+     elsif($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
+     {
+         return _GetVisualStudioVersion($1, $2);
+     }
+     croak "Unable to determine Visual Studio version: The nmake version could not be determined.";
+ }
+ 
+ sub _GetVisualStudioVersion
+ {
+     my($major, $minor) = @_;
+     if ($major > 10)
+     {
+         carp
+ "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
+         return '10.00';
+     }
+     elsif ($major < 6)
+     {
+         croak
+ "Unable to determine Visual Studio version: Visual Studio versions before 6.0 aren't supported.";
+     }
+     return "$major.$minor";
+ }
+ 
+ 1;
diff -Napcdr -x .git postgresql/src/tools/msvc/build.pl postgresql_dev/src/tools/msvc/build.pl
*** postgresql/src/tools/msvc/build.pl	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/build.pl	Sat Dec 31 23:07:00 2011
*************** our $config;
*** 33,39 ****
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
--- 33,39 ----
  require "config_default.pl";
  require "config.pl" if (-f "src/tools/msvc/config.pl");
  
! my $vcver = Mkvcbuild::mkvcbuild($config);
  
  # check what sort of build we are doing
  
*************** elsif ($ARGV[0] ne "RELEASE")
*** 50,56 ****
  
  # ... and do it
  
! if ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
--- 50,60 ----
  
  # ... and do it
  
! if ($buildwhat and $vcver eq '10.00')
! {
!     system("msbuild $buildwhat.vcxproj /verbosity:detailed /p:Configuration=$bconf");
! }
! elsif ($buildwhat)
  {
      system("vcbuild $buildwhat.vcproj $bconf");
  }
diff -Napcdr -x .git postgresql/src/tools/msvc/builddoc.pl postgresql_dev/src/tools/msvc/builddoc.pl
*** postgresql/src/tools/msvc/builddoc.pl	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/builddoc.pl	Sat Dec 31 23:07:00 2011
*************** $cmd =
*** 69,76 ****
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd ="perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "
!   ."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
--- 69,76 ----
    ."| findstr /V \"DTDDECL catalog entries are not supported\" ";
  system($cmd); # die "openjade" if $?;
  print "Running collateindex...\n";
! $cmd =
!   "perl \"$docroot/$dsssl/bin/collateindex.pl\" -f -g -i bookindex "."-o bookindex.sgml HTML.index";
  system($cmd);
  die "collateindex" if $?;
  mkdir "html";
diff -Napcdr -x .git postgresql/src/tools/msvc/clean.bat postgresql_dev/src/tools/msvc/clean.bat
*** postgresql/src/tools/msvc/clean.bat	Sun Dec 25 20:45:58 2011
--- postgresql_dev/src/tools/msvc/clean.bat	Sat Dec 31 23:07:00 2011
*************** if exist ..\msvc if exist ..\..\..\src c
*** 10,17 ****
--- 10,21 ----
  if exist debug rd /s /q debug
  if exist release rd /s /q release
  for %%f in (*.vcproj) do del %%f
+ for %%f in (*.vcxproj) do del %%f
+ for %%f in (*.vcxproj.user) do del %%f
  if exist pgsql.sln del /q pgsql.sln
  if exist pgsql.sln.cache del /q pgsql.sln.cache
+ if exist pgsql.sdf del /q pgsql.sdf
+ if exist pgsql.suo del /q /a:H pgsql.suo
  del /s /q src\bin\win32ver.rc 2> NUL
  del /s /q src\interfaces\win32ver.rc 2> NUL
  if exist src\backend\win32ver.rc del /q src\backend\win32ver.rc
#38Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#37)
Re: Review of VS 2010 support patches

On 12/31/2011 06:10 PM, Brar Piening wrote:

Brar Piening wrote:

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010? Are
there any compiler warnings?

I was able to nail down the problem.

In the absence of reaction, to keep my promise, I'm sending the
attached Patch which restores the previous working behaviour for
Visual Studio 2011.
Note however that it also restores the previous conflicts with errno.h
which aren't neccessarily a problem, but might be in future.

Yeah, are we bothered by this?:

    +  * For Microsoft Visual Studio 2010 and above we intentionally redefine
    +  * the regular Berkeley error constants and set them to the WSA constants.
    +  * Note that this will break if those constants are used for anything else
    +  * than Windows Sockets errors.

cheers

andrew

#39Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#38)
Re: Review of VS 2010 support patches

On Jan 2, 2012 12:02 AM, "Andrew Dunstan" <andrew@dunslane.net> wrote:

On 12/31/2011 06:10 PM, Brar Piening wrote:

Brar Piening wrote:

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010? Are

there any compiler warnings?

I was able to nail down the problem.

In the absence of reaction, to keep my promise, I'm sending the attached

Patch which restores the previous working behaviour for Visual Studio 2011.

Note however that it also restores the previous conflicts with errno.h

which aren't neccessarily a problem, but might be in future.

Yeah, are we bothered by this?:

+ * For Microsoft Visual Studio 2010 and above we intentionally

redefine

+ * the regular Berkeley error constants and set them to the WSA

constants.

+ * Note that this will break if those constants are used for anything

else

+ * than Windows Sockets errors.

If it's exposed to libpq clients, that's perhaps a problem. If it's just
internally and possibly for server extensions I don't think it's a problem
- unless it creates an incompatibility between msvc and mingw, but I don't
think it should?

/Magnus

#40Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#39)
Re: Review of VS 2010 support patches

On 01/02/2012 09:51 AM, Magnus Hagander wrote:

On Jan 2, 2012 12:02 AM, "Andrew Dunstan" <andrew@dunslane.net
<mailto:andrew@dunslane.net>> wrote:

On 12/31/2011 06:10 PM, Brar Piening wrote:

Brar Piening wrote:

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010?

Are there any compiler warnings?

I was able to nail down the problem.

In the absence of reaction, to keep my promise, I'm sending the

attached Patch which restores the previous working behaviour for
Visual Studio 2011.

Note however that it also restores the previous conflicts with

errno.h which aren't neccessarily a problem, but might be in future.

Yeah, are we bothered by this?:

+ * For Microsoft Visual Studio 2010 and above we intentionally

redefine

+ * the regular Berkeley error constants and set them to the WSA

constants.

+ * Note that this will break if those constants are used for

anything else

+ * than Windows Sockets errors.

If it's exposed to libpq clients, that's perhaps a problem. If it's
just internally and possibly for server extensions I don't think it's
a problem - unless it creates an incompatibility between msvc and
mingw, but I don't think it should?

Fair enough. Looks like it won't pollute libpq clients. Arguably server
extensions could be a bit of a risk though.

I'll review the rest.

cheers

andrew

#41Andrew Dunstan
andrew@dunslane.net
In reply to: Brar Piening (#37)
Re: Review of VS 2010 support patches

On 12/31/2011 06:10 PM, Brar Piening wrote:

Brar Piening wrote:

Andrew Dunstan wrote:

Can you narrow down exactly what in that commit broke VS 2010? Are
there any compiler warnings?

I was able to nail down the problem.

In the absence of reaction, to keep my promise, I'm sending the
attached Patch which restores the previous working behaviour for
Visual Studio 2011.
Note however that it also restores the previous conflicts with errno.h
which aren't neccessarily a problem, but might be in future.

OK, committed with a minor change to remove another compiler warning.

cheers

andrew