21 if (!($options->{xslt} && $options->{iconv}))
23 die "XML requires both XSLT and ICONV\n";
29 # Return 1 if $oldfile is newer than $newfile, or if $newfile doesn't exist.
30 # Special case - if config.pl has changed, always return 1
33 my ($newfile, $oldfile) = @_;
34 if ($oldfile ne 'src\tools\msvc\config.pl')
36 return 1 if IsNewer($newfile, 'src\tools\msvc\config.pl');
38 return 1 if (!(-e $newfile));
39 my @nstat = stat($newfile);
40 my @ostat = stat($oldfile);
41 return 1 if ($nstat[9] < $ostat[9]);
45 # Copy a file, *not* preserving date. Only works for text files.
48 my ($src, $dest) = @_;
49 open(I,$src) || croak "Could not open $src";
50 open(O,">$dest") || croak "Could not open $dest";
63 # Parse configure.in to get version numbers
64 open(C,"configure.in") || confess("Could not open configure.in for reading\n");
67 if (/^AC_INIT\(\[PostgreSQL\], \[([^\]]+)\]/)
70 if ($self->{strver} !~ /^(\d+)\.(\d+)(?:\.(\d+))?/)
72 confess "Bad format of version: $self->{strver}\n";
74 $self->{numver} = sprintf("%d%02d%02d", $1, $2, $3?$3:0);
75 $self->{majorver} = sprintf("%d.%d", $1, $2);
79 confess "Unable to parse configure.in for all variables!"
80 if ($self->{strver} eq '' || $self->{numver} eq '');
82 if (IsNewer("src\\include\\pg_config_os.h","src\\include\\port\\win32.h"))
84 print "Copying pg_config_os.h...\n";
85 copyFile("src\\include\\port\\win32.h","src\\include\\pg_config_os.h");
88 if (IsNewer("src\\include\\pg_config.h","src\\include\\pg_config.h.win32"))
90 print "Generating pg_config.h...\n";
91 open(I,"src\\include\\pg_config.h.win32") || confess "Could not open pg_config.h.win32\n";
92 open(O,">src\\include\\pg_config.h") || confess "Could not write to pg_config.h\n";
95 s{PG_VERSION "[^"]+"}{PG_VERSION "$self->{strver}"};
96 s{PG_VERSION_NUM \d+}{PG_VERSION_NUM $self->{numver}};
97 s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY(z)\n#define PG_VERSION_STR "PostgreSQL $self->{strver}, compiled by Visual C++ build " __STRINGIFY2(_MSC_VER)};
100 print O "/* defines added by config steps */\n";
101 print O "#define USE_ASSERT_CHECKING 1\n" if ($self->{options}->{asserts});
102 print O "#define USE_INTEGER_DATETIMES 1\n" if ($self->{options}->{integer_datetimes});
103 print O "#define USE_LDAP 1\n" if ($self->{options}->{ldap});
104 print O "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
105 print O "#define USE_SSL 1\n" if ($self->{options}->{openssl});
106 print O "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
107 print O "#define LOCALEDIR \"/share/locale\"\n" if ($self->{options}->{nls});
109 if ($self->{options}->{xml})
111 print O "#define HAVE_LIBXML2\n";
112 print O "#define USE_LIBXML\n";
114 if ($self->{options}->{krb5})
116 print O "#define KRB5 1\n";
117 print O "#define HAVE_KRB5_ERROR_TEXT_DATA 1\n";
118 print O "#define HAVE_KRB5_TICKET_ENC_PART2 1\n";
119 print O "#define PG_KRB_SRVNAM \"postgres\"\n";
125 if (IsNewer("src\\interfaces\\libpq\\libpqdll.def","src\\interfaces\\libpq\\exports.txt"))
127 print "Generating libpqdll.def...\n";
128 open(I,"src\\interfaces\\libpq\\exports.txt") || confess("Could not open exports.txt\n");
129 open(O,">src\\interfaces\\libpq\\libpqdll.def") || confess("Could not open libpqdll.def\n");
130 print O "LIBRARY LIBPQ\nEXPORTS\n";
135 print O " $f @ $o\n";
141 if (IsNewer("src\\backend\\utils\\fmgrtab.c","src\\include\\catalog\\pg_proc.h"))
143 print "Generating fmgrtab.c and fmgroids.h...\n";
144 open(I,"src\\include\\catalog\\pg_proc.h") || confess "Could not open pg_proc.h";
149 next unless (/^DATA/);
150 s/^.*OID[^=]*=[^0-9]*//;
154 next if ($p[4] ne "12");
167 open(H,'>', 'src\include\utils\fmgroids.h')
168 ||confess "Could not open fmgroids.h";
170 "/* fmgroids.h generated for Visual C++ */\n#ifndef FMGROIDS_H\n#define FMGROIDS_H\n\n";
171 open(T,">src\\backend\\utils\\fmgrtab.c") || confess "Could not open fmgrtab.c";
173 "/* fmgrtab.c generated for Visual C++ */\n#include \"postgres.h\"\n#include \"utils/fmgrtab.h\"\n\n";
174 foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr)
176 next if $seenit{$s->{prosrc}};
177 $seenit{$s->{prosrc}} = 1;
178 print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n";
179 print T "extern Datum $s->{prosrc} (PG_FUNCTION_ARGS);\n";
181 print H "\n#endif\n /* FMGROIDS_H */\n";
183 print T "const FmgrBuiltin fmgr_builtins[] = {\n";
186 $bmap{'f'} = 'false';
187 foreach my $s (sort {$a->{oid} <=> $b->{oid}} @fmgr)
190 " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n";
194 " { 0, NULL, 0, false, false, NULL }\n};\n\nconst int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1;\n";
198 if (IsNewer('src\interfaces\libpq\libpq.rc','src\interfaces\libpq\libpq.rc.in'))
200 print "Generating libpq.rc...\n";
201 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
202 my $d = ($year - 100) . "$yday";
203 open(I,'<', 'src\interfaces\libpq\libpq.rc.in') || confess "Could not open libpq.rc.in";
204 open(O,'>', 'src\interfaces\libpq\libpq.rc') || confess "Could not open libpq.rc";
207 s/(VERSION.*),0/$1,$d/;
214 if (IsNewer('src\bin\psql\sql_help.h','src\bin\psql\create_help.pl'))
216 print "Generating sql_help.h...\n";
217 chdir('src\bin\psql');
218 system("perl create_help.pl ../../../doc/src/sgml/ref sql_help.h");
224 'src\interfaces\ecpg\include\ecpg_config.h',
225 'src\interfaces\ecpg\include\ecpg_config.h.in'
229 print "Generating ecpg_config.h...\n";
230 open(O,'>','src\interfaces\ecpg\include\ecpg_config.h')
231 || confess "Could not open ecpg_config.h";
233 #if (_MSC_VER > 1200)
234 #define HAVE_LONG_LONG_INT_64
240 unless (-f "src\\port\\pg_config_paths.h")
242 print "Generating pg_config_paths.h...\n";
243 open(O,'>', 'src\port\pg_config_paths.h') || confess "Could not open pg_config_paths.h";
245 #define PGBINDIR "/bin"
246 #define PGSHAREDIR "/share"
247 #define SYSCONFDIR "/etc"
248 #define INCLUDEDIR "/include"
249 #define PKGINCLUDEDIR "/include"
250 #define INCLUDEDIRSERVER "/include/server"
251 #define LIBDIR "/lib"
252 #define PKGLIBDIR "/lib"
253 #define LOCALEDIR "/share/locale"
254 #define DOCDIR "/doc"
255 #define MANDIR "/man"
260 my $mf = Project::read_file('src\backend\catalog\Makefile');
261 $mf =~ s{\\s*[\r\n]+}{}mg;
262 $mf =~ /^POSTGRES_BKI_SRCS\s*:?=[^,]+,(.*)\)$/gm
263 || croak "Could not find POSTGRES_BKI_SRCS in Makefile\n";
264 my @allbki = split /\s+/, $1;
265 foreach my $bki (@allbki)
268 if (IsNewer('src/backend/catalog/postgres.bki', "src/include/catalog/$bki"))
270 print "Generating postgres.bki...\n";
273 "src/backend/catalog/postgres",
274 split(/ /,join(' src/include/catalog/',@allbki))
280 open(O, ">doc/src/sgml/version.sgml") || croak "Could not write to version.sgml\n";
282 <!entity version "$self->{strver}">
283 <!entity majorversion "$self->{majorver}">
290 my ($self, $name, $type, $folder, $initialdir) = @_;
292 my $proj = new Project($name, $type, $self);
293 push @{$self->{projects}->{$folder}}, $proj;
294 $proj->AddDir($initialdir) if ($initialdir);
295 if ($self->{options}->{zlib})
297 $proj->AddIncludeDir($self->{options}->{zlib} . '\include');
298 $proj->AddLibrary($self->{options}->{zlib} . '\lib\zdll.lib');
300 if ($self->{options}->{openssl})
302 $proj->AddIncludeDir($self->{options}->{openssl} . '\include');
303 $proj->AddLibrary($self->{options}->{openssl} . '\lib\VC\ssleay32.lib', 1);
304 $proj->AddLibrary($self->{options}->{openssl} . '\lib\VC\libeay32.lib', 1);
306 if ($self->{options}->{nls})
308 $proj->AddIncludeDir($self->{options}->{nls} . '\include');
309 $proj->AddLibrary($self->{options}->{nls} . '\lib\intl.lib');
311 if ($self->{options}->{krb5})
313 $proj->AddIncludeDir($self->{options}->{krb5} . '\inc\krb5');
314 $proj->AddLibrary($self->{options}->{krb5} . '\lib\i386\krb5_32.lib');
315 $proj->AddLibrary($self->{options}->{krb5} . '\lib\i386\comerr32.lib');
317 if ($self->{options}->{xml})
319 $proj->AddIncludeDir($self->{options}->{xml} . '\include');
320 $proj->AddIncludeDir($self->{options}->{iconv} . '\include');
321 $proj->AddLibrary($self->{options}->{xml} . '\lib\libxml2.lib');
331 $self->GenerateFiles();
332 foreach my $fld (keys %{$self->{projects}})
334 foreach my $proj (@{$self->{projects}->{$fld}})
340 open(SLN,">pgsql.sln") || croak "Could not write to pgsql.sln\n";
342 Microsoft Visual Studio Solution File, Format Version 9.00
346 foreach my $fld (keys %{$self->{projects}})
348 foreach my $proj (@{$self->{projects}->{$fld}})
351 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "$proj->{name}", "$proj->{name}.vcproj", "$proj->{guid}"
357 $flduid{$fld} = Win32::GuidGen();
359 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$fld", "$fld", "$flduid{$fld}"
367 GlobalSection(SolutionConfigurationPlatforms) = preSolution
368 Debug|Win32 = Debug|Win32
369 Release|Win32 = Release|Win32
371 GlobalSection(ProjectConfigurationPlatforms) = postSolution
374 foreach my $fld (keys %{$self->{projects}})
376 foreach my $proj (@{$self->{projects}->{$fld}})
379 $proj->{guid}.Debug|Win32.ActiveCfg = Debug|Win32
380 $proj->{guid}.Debug|Win32.Build.0 = Debug|Win32
381 $proj->{guid}.Release|Win32.ActiveCfg = Release|Win32
382 $proj->{guid}.Release|Win32.Build.0 = Release|Win32
389 GlobalSection(SolutionProperties) = preSolution
390 HideSolutionNode = FALSE
392 GlobalSection(NestedProjects) = preSolution
395 foreach my $fld (keys %{$self->{projects}})
397 next if ($fld eq "");
398 foreach my $proj (@{$self->{projects}->{$fld}})
400 print SLN "\t\t$proj->{guid} = $flduid{$fld}\n";