2006-09-04 23:30:40 +02:00
|
|
|
package Project;
|
2007-03-29 17:30:52 +02:00
|
|
|
|
2007-03-17 15:01:01 +01:00
|
|
|
#
|
|
|
|
# Package that encapsulates a Visual C++ project file generation
|
|
|
|
#
|
2010-09-20 22:08:53 +02:00
|
|
|
# src/tools/msvc/Project.pm
|
2007-03-17 15:01:01 +01:00
|
|
|
#
|
2006-09-04 23:30:40 +02:00
|
|
|
use Carp;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2007-08-21 17:10:41 +02:00
|
|
|
use File::Basename;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-01-03 14:44:26 +01:00
|
|
|
sub _new
|
2007-03-12 20:10:50 +01:00
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($classname, $name, $type, $solution) = @_;
|
|
|
|
my $good_types = {
|
|
|
|
lib => 1,
|
|
|
|
exe => 1,
|
2012-07-05 03:47:49 +02:00
|
|
|
dll => 1, };
|
2012-06-10 21:20:04 +02:00
|
|
|
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 => '',
|
2012-07-05 03:47:49 +02:00
|
|
|
platform => $solution->{platform}, };
|
2012-06-10 21:20:04 +02:00
|
|
|
|
|
|
|
bless($self, $classname);
|
|
|
|
return $self;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddFile
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $filename) = @_;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->{files}->{$filename} = 1;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddFiles
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my $self = shift;
|
2012-07-05 03:47:49 +02:00
|
|
|
my $dir = shift;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
while (my $f = shift)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
$self->{files}->{ $dir . "\\" . $f } = 1;
|
2012-06-10 21:20:04 +02:00
|
|
|
}
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub ReplaceFile
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $filename, $newname) = @_;
|
|
|
|
my $re = "\\\\$filename\$";
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $file (keys %{ $self->{files} })
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
# Match complete filename
|
|
|
|
if ($filename =~ /\\/)
|
|
|
|
{
|
|
|
|
if ($file eq $filename)
|
|
|
|
{
|
|
|
|
delete $self->{files}{$file};
|
|
|
|
$self->{files}{$newname} = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($file =~ m/($re)/)
|
|
|
|
{
|
|
|
|
delete $self->{files}{$file};
|
|
|
|
$self->{files}{"$newname\\$filename"} = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
confess("Could not find file $filename to replace\n");
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub RemoveFile
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $filename) = @_;
|
2012-07-05 03:47:49 +02:00
|
|
|
my $orig = scalar keys %{ $self->{files} };
|
2012-06-10 21:20:04 +02:00
|
|
|
delete $self->{files}->{$filename};
|
2012-07-05 03:47:49 +02:00
|
|
|
if ($orig > scalar keys %{ $self->{files} })
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
confess("Could not find file $filename to remove\n");
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 17:10:41 +02:00
|
|
|
sub RelocateFiles
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $targetdir, $proc) = @_;
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $f (keys %{ $self->{files} })
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
my $r = &$proc($f);
|
|
|
|
if ($r)
|
|
|
|
{
|
|
|
|
$self->RemoveFile($f);
|
|
|
|
$self->AddFile($targetdir . '\\' . basename($f));
|
|
|
|
}
|
|
|
|
}
|
2007-08-21 17:10:41 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddReference
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my $self = shift;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
while (my $ref = shift)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
push @{ $self->{references} }, $ref;
|
|
|
|
$self->AddLibrary(
|
|
|
|
"__CFGNAME__\\" . $ref->{name} . "\\" . $ref->{name} . ".lib");
|
2012-06-10 21:20:04 +02:00
|
|
|
}
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddLibrary
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $lib, $dbgsuffix) = @_;
|
|
|
|
|
|
|
|
if ($lib =~ m/\s/)
|
|
|
|
{
|
|
|
|
$lib = '"' . $lib . """;
|
|
|
|
}
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
push @{ $self->{libraries} }, $lib;
|
2012-06-10 21:20:04 +02:00
|
|
|
if ($dbgsuffix)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
push @{ $self->{suffixlib} }, $lib;
|
2012-06-10 21:20:04 +02:00
|
|
|
}
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddIncludeDir
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $inc) = @_;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
if ($self->{includes} ne '')
|
|
|
|
{
|
|
|
|
$self->{includes} .= ';';
|
|
|
|
}
|
|
|
|
$self->{includes} .= $inc;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-06-12 20:31:28 +02:00
|
|
|
sub AddPrefixInclude
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $inc) = @_;
|
2007-06-12 20:31:28 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->{prefixincludes} = $inc . ';' . $self->{prefixincludes};
|
2007-06-12 20:31:28 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddDefine
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $def) = @_;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
$def =~ s/"/""/g;
|
|
|
|
$self->{defines} .= $def . ';';
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub FullExportDLL
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $libname) = @_;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->{builddef} = 1;
|
2012-07-05 03:47:49 +02:00
|
|
|
$self->{def} = ".\\__CFGNAME__\\$self->{name}\\$self->{name}.def";
|
|
|
|
$self->{implib} = "__CFGNAME__\\$self->{name}\\$libname";
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub UseDef
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $def) = @_;
|
2006-09-04 23:30:40 +02:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->{def} = $def;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddDir
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $reldir) = @_;
|
|
|
|
my $MF;
|
|
|
|
|
|
|
|
my $t = $/;
|
|
|
|
undef $/;
|
2012-07-05 03:47:49 +02:00
|
|
|
open($MF, "$reldir\\Makefile")
|
|
|
|
|| open($MF, "$reldir\\GNUMakefile")
|
2012-06-10 21:20:04 +02:00
|
|
|
|| croak "Could not open $reldir\\Makefile\n";
|
|
|
|
my $mf = <$MF>;
|
|
|
|
close($MF);
|
|
|
|
|
|
|
|
$mf =~ s{\\\s*[\r\n]+}{}mg;
|
|
|
|
if ($mf =~ m{^(?:SUB)?DIRS[^=]*=\s*(.*)$}mg)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $subdir (split /\s+/, $1)
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
next
|
|
|
|
if $subdir eq "\$(top_builddir)/src/timezone"
|
2012-07-05 03:47:49 +02:00
|
|
|
; #special case for non-standard include
|
2012-06-10 21:20:04 +02:00
|
|
|
next
|
|
|
|
if $reldir . "\\" . $subdir eq "src\\backend\\port\\darwin";
|
|
|
|
|
|
|
|
$self->AddDir($reldir . "\\" . $subdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ($mf =~ m{^(?:EXTRA_)?OBJS[^=]*=\s*(.*)$}m)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
my $s = $1;
|
2012-06-10 21:20:04 +02:00
|
|
|
my $filter_re = qr{\$\(filter ([^,]+),\s+\$\(([^\)]+)\)\)};
|
|
|
|
while ($s =~ /$filter_re/)
|
|
|
|
{
|
|
|
|
|
|
|
|
# Process $(filter a b c, $(VAR)) expressions
|
2012-07-05 03:47:49 +02:00
|
|
|
my $list = $1;
|
2012-06-10 21:20:04 +02:00
|
|
|
my $filter = $2;
|
|
|
|
$list =~ s/\.o/\.c/g;
|
|
|
|
my @pieces = split /\s+/, $list;
|
|
|
|
my $matches = "";
|
|
|
|
foreach my $p (@pieces)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($filter eq "LIBOBJS")
|
|
|
|
{
|
|
|
|
if (grep(/$p/, @main::pgportfiles) == 1)
|
|
|
|
{
|
|
|
|
$p =~ s/\.c/\.o/;
|
|
|
|
$matches .= $p . " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess "Unknown filter $filter\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$s =~ s/$filter_re/$matches/;
|
|
|
|
}
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $f (split /\s+/, $s)
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
next if $f =~ /^\s*$/;
|
|
|
|
next if $f eq "\\";
|
|
|
|
next if $f =~ /\/SUBSYS.o$/;
|
2012-07-05 03:47:49 +02:00
|
|
|
$f =~ s/,$//
|
|
|
|
; # Remove trailing comma that can show up from filter stuff
|
2012-06-10 21:20:04 +02:00
|
|
|
next unless $f =~ /.*\.o$/;
|
|
|
|
$f =~ s/\.o$/\.c/;
|
|
|
|
if ($f =~ /^\$\(top_builddir\)\/(.*)/)
|
|
|
|
{
|
|
|
|
$f = $1;
|
|
|
|
$f =~ s/\//\\/g;
|
|
|
|
$self->{files}->{$f} = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$f =~ s/\//\\/g;
|
|
|
|
$self->{files}->{"$reldir\\$f"} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mf =~ s{OBJS[^=]*=\s*(.*)$}{}m;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Match rules that pull in source files from different directories, eg
|
|
|
|
# pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
|
2012-07-05 03:47:49 +02:00
|
|
|
my $replace_re =
|
|
|
|
qr{^([^:\n\$]+\.c)\s*:\s*(?:%\s*: )?\$(\([^\)]+\))\/(.*)\/[^\/]+$}m;
|
2012-06-10 21:20:04 +02:00
|
|
|
while ($mf =~ m{$replace_re}m)
|
|
|
|
{
|
2012-07-05 03:47:49 +02:00
|
|
|
my $match = $1;
|
|
|
|
my $top = $2;
|
2012-06-10 21:20:04 +02:00
|
|
|
my $target = $3;
|
|
|
|
$target =~ s{/}{\\}g;
|
2012-07-05 03:47:49 +02:00
|
|
|
my @pieces = split /\s+/, $match;
|
2012-06-10 21:20:04 +02:00
|
|
|
foreach my $fn (@pieces)
|
|
|
|
{
|
|
|
|
if ($top eq "(top_srcdir)")
|
|
|
|
{
|
|
|
|
eval { $self->ReplaceFile($fn, $target) };
|
|
|
|
}
|
|
|
|
elsif ($top eq "(backend_src)")
|
|
|
|
{
|
|
|
|
eval { $self->ReplaceFile($fn, "src\\backend\\$target") };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess "Bad replacement top: $top, on line $_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mf =~ s{$replace_re}{}m;
|
|
|
|
}
|
|
|
|
|
|
|
|
# See if this Makefile contains a description, and should have a RC file
|
|
|
|
if ($mf =~ /^PGFILEDESC\s*=\s*\"([^\"]+)\"/m)
|
|
|
|
{
|
|
|
|
my $desc = $1;
|
|
|
|
my $ico;
|
|
|
|
if ($mf =~ /^PGAPPICON\s*=\s*(.*)$/m) { $ico = $1; }
|
2012-07-05 03:47:49 +02:00
|
|
|
$self->AddResourceFile($reldir, $desc, $ico);
|
2012-06-10 21:20:04 +02:00
|
|
|
}
|
|
|
|
$/ = $t;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub AddResourceFile
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $dir, $desc, $ico) = @_;
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
|
|
|
|
localtime(time);
|
2012-06-10 21:20:04 +02:00
|
|
|
my $d = ($year - 100) . "$yday";
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
if (Solution::IsNewer("$dir\\win32ver.rc", 'src\port\win32ver.rc'))
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
print "Generating win32ver.rc for $dir\n";
|
2012-07-05 03:47:49 +02:00
|
|
|
open(I, 'src\port\win32ver.rc')
|
|
|
|
|| confess "Could not open win32ver.rc";
|
|
|
|
open(O, ">$dir\\win32ver.rc")
|
|
|
|
|| confess "Could not write win32ver.rc";
|
|
|
|
my $icostr = $ico ? "IDI_ICON ICON \"src/port/$ico.ico\"" : "";
|
2012-06-10 21:20:04 +02:00
|
|
|
while (<I>)
|
|
|
|
{
|
|
|
|
s/FILEDESC/"$desc"/gm;
|
|
|
|
s/_ICO_/$icostr/gm;
|
|
|
|
s/(VERSION.*),0/$1,$d/;
|
|
|
|
if ($self->{type} eq "dll")
|
|
|
|
{
|
|
|
|
s/VFT_APP/VFT_DLL/gm;
|
|
|
|
}
|
|
|
|
print O;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(O);
|
|
|
|
close(I);
|
|
|
|
$self->AddFile("$dir\\win32ver.rc");
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub DisableLinkerWarnings
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $warnings) = @_;
|
2007-01-26 18:45:42 +01:00
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
$self->{disablelinkerwarnings} .= ','
|
|
|
|
unless ($self->{disablelinkerwarnings} eq '');
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->{disablelinkerwarnings} .= $warnings;
|
2007-01-26 18:45:42 +01:00
|
|
|
}
|
|
|
|
|
2007-03-12 20:10:50 +01:00
|
|
|
sub Save
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self) = @_;
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# If doing DLL and haven't specified a DEF file, do a full export of all symbols
|
|
|
|
# in the project.
|
2012-06-10 21:20:04 +02:00
|
|
|
if ($self->{type} eq "dll" && !$self->{def})
|
|
|
|
{
|
|
|
|
$self->FullExportDLL($self->{name} . ".lib");
|
|
|
|
}
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
# Warning 4197 is about double exporting, disable this per
|
|
|
|
# http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99193
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->DisableLinkerWarnings('4197') if ($self->{platform} eq 'x64');
|
|
|
|
|
|
|
|
# Dump the project
|
|
|
|
open(F, ">$self->{name}$self->{filenameExtension}")
|
2012-07-05 03:47:49 +02:00
|
|
|
|| croak(
|
|
|
|
"Could not write to $self->{name}$self->{filenameExtension}\n");
|
2012-06-10 21:20:04 +02:00
|
|
|
$self->WriteHeader(*F);
|
|
|
|
$self->WriteFiles(*F);
|
|
|
|
$self->Footer(*F);
|
|
|
|
close(F);
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2012-01-03 14:44:26 +01:00
|
|
|
sub GetAdditionalLinkerDependencies
|
2007-03-12 20:10:50 +01:00
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my ($self, $cfgname, $seperator) = @_;
|
2012-07-05 03:47:49 +02:00
|
|
|
my $libcfg = (uc $cfgname eq "RELEASE") ? "MD" : "MDd";
|
2012-06-10 21:20:04 +02:00
|
|
|
my $libs = '';
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $lib (@{ $self->{libraries} })
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
my $xlib = $lib;
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $slib (@{ $self->{suffixlib} })
|
2012-06-10 21:20:04 +02:00
|
|
|
{
|
|
|
|
if ($slib eq $lib)
|
|
|
|
{
|
|
|
|
$xlib =~ s/\.lib$/$libcfg.lib/;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$libs .= $xlib . $seperator;
|
|
|
|
}
|
|
|
|
$libs =~ s/.$//;
|
|
|
|
$libs =~ s/__CFGNAME__/$cfgname/g;
|
|
|
|
return $libs;
|
2006-09-04 23:30:40 +02:00
|
|
|
}
|
|
|
|
|
2006-10-22 19:17:09 +02:00
|
|
|
# Utility function that loads a complete file
|
2007-03-12 20:10:50 +01:00
|
|
|
sub read_file
|
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
my $filename = shift;
|
|
|
|
my $F;
|
|
|
|
my $t = $/;
|
2007-03-12 20:10:50 +01:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
undef $/;
|
|
|
|
open($F, $filename) || croak "Could not open file $filename\n";
|
|
|
|
my $txt = <$F>;
|
|
|
|
close($F);
|
|
|
|
$/ = $t;
|
2007-03-12 20:10:50 +01:00
|
|
|
|
2012-06-10 21:20:04 +02:00
|
|
|
return $txt;
|
2006-10-22 19:17:09 +02:00
|
|
|
}
|
|
|
|
|
2006-09-04 23:30:40 +02:00
|
|
|
1;
|