#!c:/perl/bin/perl

# $PostgreSQL$

# keep this in case we need it some time - it's not really needed ATM

use Cwd;

my $start_dir = getcwd();

# buildenv.pl is for specifying the build environment settings
# it should contian lines like:
# $ENV{PATH} = "c:/path/to/bison/bin;$ENV{PATH}";

if ( -e "src/tools/msvc/buildenv.pl")
{
    require "src/tools/msvc/buildenv.pl";
}
elsif (-e "./buildenv.pl" )
{
    require "./buildenv.pl";
}

# mkvcbuild.pl sets up the project for us

system("perl mkvcbuild.pl");

my $status = $? >> 8;

exit $status if $status;

# go to top build dir

chdir("../../..") if  (-d "../msvc" && -d "../../../src");

# check what sort of build we are doing

my $config = "Release";
my $buildwhat = $ARGV[1] || "";
if ($ARGV[0] eq 'DEBUG')
{
    $config = "Debug";
}
elsif ($ARGV[0] ne "RELEASE")
{
    $buildwhat = $ARGV[0] || "";
}

# ... and do it

if ($buildwhat)
{
    system("vcbuild $buildwhat.vcproj $config");
}
else
{
    system("msbuild pgsql.sln /verbosity:detailed /p:Configuration=$config");
}

# report status

$status = $? >> 8;

exit $status;
