Skip to content

Commit 66ece31

Browse files
committed
Refactor Mkvcbuild.pm to facilitate modules migrations
This is in preparation to "upgrade" some modules from contrib/ to src/bin/, per discussion. Author: Michael Paquier
1 parent 57aa5b2 commit 66ece31

File tree

1 file changed

+81
-40
lines changed

1 file changed

+81
-40
lines changed

src/tools/msvc/Mkvcbuild.pm

+81-40
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ my $libpgcommon;
2929
my $postgres;
3030
my $libpq;
3131

32+
# Set of variables for contrib modules
3233
my $contrib_defines = { 'refint' => 'REFINT_VERBOSE' };
3334
my @contrib_uselibpq =
3435
('dblink', 'oid2name', 'pgbench', 'pg_upgrade', 'postgres_fdw', 'vacuumlo');
@@ -48,11 +49,25 @@ my $contrib_extralibs = { 'pgbench' => ['ws2_32.lib'] };
4849
my $contrib_extraincludes =
4950
{ 'tsearch2' => ['contrib/tsearch2'], 'dblink' => ['src/backend'] };
5051
my $contrib_extrasource = {
51-
'cube' => [ 'cubescan.l', 'cubeparse.y' ],
52-
'pgbench' => [ 'exprscan.l', 'exprparse.y' ],
53-
'seg' => [ 'segscan.l', 'segparse.y' ], };
52+
'cube' => [ 'contrib\cube\cubescan.l', 'contrib\cube\cubeparse.y' ],
53+
'pgbench' =>
54+
[ 'contrib\pgbench\exprscan.l', 'contrib\pgbench\exprparse.y' ],
55+
'seg' => [ 'contrib\seg\segscan.l', 'contrib\seg\segparse.y' ], };
5456
my @contrib_excludes = ('pgcrypto', 'intagg', 'sepgsql');
5557

58+
# Set of variables for frontend modules
59+
my $frontend_defines = { 'initdb' => 'FRONTEND' };
60+
my @frontend_uselibpq = ('pg_ctl', 'psql');
61+
my $frontend_extralibs = {
62+
'initdb' => ['ws2_32.lib'],
63+
'pg_restore' => ['ws2_32.lib'],
64+
'psql' => ['ws2_32.lib'] };
65+
my $frontend_extraincludes = {
66+
'initdb' => ['src\timezone'],
67+
'psql' => [ 'src\bin\pg_dump', 'src\backend' ] };
68+
my $frontend_extrasource = { 'psql' => ['src\bin\psql\psqlscan.l'] };
69+
my @frontend_excludes = ('pgevent', 'pg_basebackup', 'pg_dump', 'scripts');
70+
5671
sub mkvcbuild
5772
{
5873
our $config = shift;
@@ -108,6 +123,7 @@ sub mkvcbuild
108123
$postgres->AddFiles('src\port', @pgportfiles);
109124
$postgres->AddFiles('src\common', @pgcommonbkndfiles);
110125
$postgres->AddDir('src\timezone');
126+
111127
# We need source files from src\timezone, but that directory's resource
112128
# file pertains to "zic", not to the backend.
113129
$postgres->RemoveFile('src\timezone\win32ver.rc');
@@ -122,15 +138,17 @@ sub mkvcbuild
122138
$postgres->AddLibrary('ws2_32.lib');
123139
$postgres->AddLibrary('wldap32.lib') if ($solution->{options}->{ldap});
124140
$postgres->FullExportDLL('postgres.lib');
125-
# The OBJS scraper doesn't know about ifdefs, so remove be-secure-openssl.c
126-
# if building without OpenSSL
141+
142+
# The OBJS scraper doesn't know about ifdefs, so remove be-secure-openssl.c
143+
# if building without OpenSSL
127144
if (!$solution->{options}->{openssl})
128145
{
129146
$postgres->RemoveFile('src\backend\libpq\be-secure-openssl.c');
130147
}
131148

132149
my $snowball = $solution->AddProject('dict_snowball', 'dll', '',
133150
'src\backend\snowball');
151+
134152
# This Makefile uses VPATH to find most source files in a subdirectory.
135153
$snowball->RelocateFiles(
136154
'src\backend\snowball\libstemmer',
@@ -288,8 +306,9 @@ sub mkvcbuild
288306
$libpq->ReplaceFile('src\interfaces\libpq\libpqrc.c',
289307
'src\interfaces\libpq\libpq.rc');
290308
$libpq->AddReference($libpgport);
291-
# The OBJS scraper doesn't know about ifdefs, so remove fe-secure-openssl.c
292-
# if building without OpenSSL
309+
310+
# The OBJS scraper doesn't know about ifdefs, so remove fe-secure-openssl.c
311+
# if building without OpenSSL
293312
if (!$solution->{options}->{openssl})
294313
{
295314
$libpq->RemoveFile('src\interfaces\libpq\fe-secure-openssl.c');
@@ -380,11 +399,15 @@ sub mkvcbuild
380399
$pgregress_isolation->AddReference($libpgcommon, $libpgport);
381400

382401
# src/bin
383-
my $initdb = AddSimpleFrontend('initdb');
384-
$initdb->AddIncludeDir('src\interfaces\libpq');
385-
$initdb->AddIncludeDir('src\timezone');
386-
$initdb->AddDefine('FRONTEND');
387-
$initdb->AddLibrary('ws2_32.lib');
402+
my $D;
403+
opendir($D, 'src/bin') || croak "Could not opendir on src/bin!\n";
404+
while (my $d = readdir($D))
405+
{
406+
next if ($d =~ /^\./);
407+
next unless (-f "src/bin/$d/Makefile");
408+
next if (grep { /^$d$/ } @frontend_excludes);
409+
AddSimpleFrontend($d);
410+
}
388411

389412
my $pgbasebackup = AddSimpleFrontend('pg_basebackup', 1);
390413
$pgbasebackup->AddFile('src\bin\pg_basebackup\pg_basebackup.c');
@@ -400,14 +423,6 @@ sub mkvcbuild
400423
$pgrecvlogical->AddFile('src\bin\pg_basebackup\pg_recvlogical.c');
401424
$pgrecvlogical->AddLibrary('ws2_32.lib');
402425

403-
my $pgconfig = AddSimpleFrontend('pg_config');
404-
405-
my $pgcontrol = AddSimpleFrontend('pg_controldata');
406-
407-
my $pgctl = AddSimpleFrontend('pg_ctl', 1);
408-
409-
my $pgreset = AddSimpleFrontend('pg_resetxlog');
410-
411426
my $pgevent = $solution->AddProject('pgevent', 'dll', 'bin');
412427
$pgevent->AddFiles('src\bin\pgevent', 'pgevent.c', 'pgmsgevent.rc');
413428
$pgevent->AddResourceFile('src\bin\pgevent', 'Eventlog message formatter',
@@ -416,12 +431,6 @@ sub mkvcbuild
416431
$pgevent->UseDef('src\bin\pgevent\pgevent.def');
417432
$pgevent->DisableLinkerWarnings('4104');
418433

419-
my $psql = AddSimpleFrontend('psql', 1);
420-
$psql->AddIncludeDir('src\bin\pg_dump');
421-
$psql->AddIncludeDir('src\backend');
422-
$psql->AddFile('src\bin\psql\psqlscan.l');
423-
$psql->AddLibrary('ws2_32.lib');
424-
425434
my $pgdump = AddSimpleFrontend('pg_dump', 1);
426435
$pgdump->AddIncludeDir('src\backend');
427436
$pgdump->AddFile('src\bin\pg_dump\pg_dump.c');
@@ -532,7 +541,6 @@ sub mkvcbuild
532541
my $mf = Project::read_file('contrib/pgcrypto/Makefile');
533542
GenerateContribSqlFiles('pgcrypto', $mf);
534543

535-
my $D;
536544
opendir($D, 'contrib') || croak "Could not opendir on contrib!\n";
537545
while (my $d = readdir($D))
538546
{
@@ -652,6 +660,10 @@ sub AddSimpleFrontend
652660
$p->AddIncludeDir('src\interfaces\libpq');
653661
$p->AddReference($libpq);
654662
}
663+
664+
# Adjust module definition using frontent variables
665+
AdjustFrontendProj($p);
666+
655667
return $p;
656668
}
657669

@@ -729,7 +741,7 @@ sub GenerateContribSqlFiles
729741
print "Building $out from $in (contrib/$n)...\n";
730742
my $cont = Project::read_file("contrib/$n/$in");
731743
my $dn = $out;
732-
$dn =~ s/\.sql$//;
744+
$dn =~ s/\.sql$//;
733745
$cont =~ s/MODULE_PATHNAME/\$libdir\/$dn/g;
734746
my $o;
735747
open($o, ">contrib/$n/$out")
@@ -744,45 +756,74 @@ sub GenerateContribSqlFiles
744756
sub AdjustContribProj
745757
{
746758
my $proj = shift;
747-
my $n = $proj->{name};
759+
AdjustModule(
760+
$proj, $contrib_defines,
761+
\@contrib_uselibpq, \@contrib_uselibpgport,
762+
\@contrib_uselibpgcommon, $contrib_extralibs,
763+
$contrib_extrasource, $contrib_extraincludes);
764+
}
748765

749-
if ($contrib_defines->{$n})
766+
sub AdjustFrontendProj
767+
{
768+
my $proj = shift;
769+
AdjustModule($proj, $frontend_defines, \@frontend_uselibpq, undef,
770+
undef, $frontend_extralibs,
771+
$frontend_extrasource, $frontend_extraincludes);
772+
}
773+
774+
sub AdjustModule
775+
{
776+
my $proj = shift;
777+
my $module_defines = shift;
778+
my $module_uselibpq = shift;
779+
my $module_uselibpgport = shift;
780+
my $module_uselibpgcommon = shift;
781+
my $module_extralibs = shift;
782+
my $module_extrasource = shift;
783+
my $module_extraincludes = shift;
784+
my $n = $proj->{name};
785+
786+
if ($module_defines->{$n})
750787
{
751-
foreach my $d ($contrib_defines->{$n})
788+
foreach my $d ($module_defines->{$n})
752789
{
753790
$proj->AddDefine($d);
754791
}
755792
}
756-
if (grep { /^$n$/ } @contrib_uselibpq)
793+
if (grep { /^$n$/ } @{$module_uselibpq})
757794
{
758795
$proj->AddIncludeDir('src\interfaces\libpq');
759796
$proj->AddReference($libpq);
760797
}
761-
if (grep { /^$n$/ } @contrib_uselibpgport)
798+
if (grep { /^$n$/ } @{$module_uselibpgport})
762799
{
763800
$proj->AddReference($libpgport);
764801
}
765-
if (grep { /^$n$/ } @contrib_uselibpgcommon)
802+
if (grep { /^$n$/ } @{$module_uselibpgcommon})
766803
{
767804
$proj->AddReference($libpgcommon);
768805
}
769-
if ($contrib_extralibs->{$n})
806+
if ($module_extralibs->{$n})
770807
{
771-
foreach my $l (@{ $contrib_extralibs->{$n} })
808+
foreach my $l (@{ $module_extralibs->{$n} })
772809
{
773810
$proj->AddLibrary($l);
774811
}
775812
}
776-
if ($contrib_extraincludes->{$n})
813+
if ($module_extraincludes->{$n})
777814
{
778-
foreach my $i (@{ $contrib_extraincludes->{$n} })
815+
foreach my $i (@{ $module_extraincludes->{$n} })
779816
{
780817
$proj->AddIncludeDir($i);
781818
}
782819
}
783-
if ($contrib_extrasource->{$n})
820+
if ($module_extrasource->{$n})
784821
{
785-
$proj->AddFiles('contrib\\' . $n, @{ $contrib_extrasource->{$n} });
822+
foreach my $i (@{ $module_extrasource->{$n} })
823+
{
824+
print "Files $i\n";
825+
$proj->AddFile($i);
826+
}
786827
}
787828
}
788829

0 commit comments

Comments
 (0)