4 # Package that provides 'make install' functionality for msvc builds
6 # $PostgreSQL: pgsql/src/tools/msvc/Install.pm,v 1.35 2010/04/09 13:05:58 mha Exp $
16 our (@ISA,@EXPORT_OK);
18 @EXPORT_OK = qw(Install);
27 unlink $target || confess "Could not delete $target\n";
31 || confess "Could not copy $src to $target\n";
41 require "config_default.pl";
42 require "config.pl" if (-f "config.pl");
44 chdir("../../..") if (-f "../../../configure");
45 chdir("../../../..") if (-f "../../../../configure");
55 die "Could not find debug or release binaries" if ($conf eq "");
56 my $majorver = DetermineMajorVersion();
57 print "Installing version $majorver for $conf in $target\n";
59 EnsureDirectories($target, 'bin','lib','share','share/timezonesets','share/contrib','doc',
60 'doc/contrib', 'symbols', 'share/tsearch_data');
62 CopySolutionOutput($conf, $target);
63 lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
64 my $sample_files = [];
69 &&push(@$sample_files, $File::Find::name);
74 CopySetOfFiles('config files', $sample_files, $target . '/share/');
78 "$conf\\", "postgres\\postgres.lib","libpq\\libpq.lib", "libecpg\\libecpg.lib",
79 "libpgport\\libpgport.lib"
83 [ glob('src\timezone\tznames\*.txt') ],
84 $target . '/share/timezonesets/'
88 $target . '/share/timezonesets/',
89 'src/timezone/tznames/', 'Default','Australia','India'
91 CopySetOfFiles('BKI files', [ glob("src\\backend\\catalog\\postgres.*") ],$target .'/share/');
92 CopySetOfFiles('SQL files', [ glob("src\\backend\\catalog\\*.sql") ],$target . '/share/');
94 'Information schema data',
96 'src/backend/catalog/', 'sql_features.txt'
98 GenerateConversionScript($target);
99 GenerateTimezoneFiles($target,$conf);
100 GenerateTsearchFiles($target);
103 [ glob("src\\backend\\snowball\\stopwords\\*.stop") ],
104 $target . '/share/tsearch_data/'
107 'Dictionaries sample files',
108 [ glob("src\\backend\\tsearch\\*_sample.*") ],
109 $target . '/share/tsearch_data/'
111 CopyContribFiles($config,$target);
112 CopyIncludeFiles($target);
114 GenerateNLSFiles($target,$config->{nls},$majorver) if ($config->{nls});
116 print "Installation complete.\n";
119 sub EnsureDirectories
122 mkdir $target unless -d ($target);
123 while (my $d = shift)
125 mkdir $target . '/' . $d unless -d ($target . '/' . $d);
135 print "Copying $what";
136 while (my $f = shift)
140 die "No file $f\n" if (!-f $f);
141 lcopy($f, $target . basename($f));
151 print "Copying $what" if $what;
154 next if /regress/; # Skip temporary install in regression subdir
155 next if /ecpg.test/; # Skip temporary install in regression subdir
156 my $tgt = $target . basename($_);
158 lcopy($_, $tgt) || croak "Could not copy $_: $!\n";
163 sub CopySolutionOutput
167 my $rem = qr{Project\("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"\) = "([^"]+)"};
169 my $sln = read_file("pgsql.sln") || croak "Could not open pgsql.sln\n";
170 print "Copying build output files...";
179 my $proj = read_file("$pf.vcproj") || croak "Could not open $pf.vcproj\n";
180 if ($proj !~ qr{ConfigurationType="([^"]+)"})
182 croak "Could not parse $pf.vcproj\n";
197 # Static lib, such as libpgport, only used internally during build, don't install
200 lcopy("$conf\\$pf\\$pf.$ext","$target\\$dir\\$pf.$ext")
201 || croak "Could not copy $pf.$ext\n";
202 lcopy("$conf\\$pf\\$pf.pdb","$target\\symbols\\$pf.pdb")
203 || croak "Could not copy $pf.pdb\n";
209 sub GenerateConversionScript
215 print "Generating conversion proc script...";
216 my $mf = read_file('src/backend/utils/mb/conversion_procs/Makefile');
217 $mf =~ s{\\\s*[\r\n]+}{}mg;
218 $mf =~ /^CONVERSIONS\s*=\s*(.*)$/m
219 || die "Could not find CONVERSIONS line in conversions Makefile\n";
220 my @pieces = split /\s+/,$1;
223 my $name = shift @pieces;
224 my $se = shift @pieces;
225 my $de = shift @pieces;
226 my $func = shift @pieces;
227 my $obj = shift @pieces;
228 $sql .= "-- $se --> $de\n";
230 "CREATE OR REPLACE FUNCTION $func (INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) RETURNS VOID AS '\$libdir/$obj', '$func' LANGUAGE C STRICT;\n";
232 "COMMENT ON FUNCTION $func(INTEGER, INTEGER, CSTRING, INTERNAL, INTEGER) IS 'internal conversion function for $se to $de';\n";
233 $sql .= "DROP CONVERSION pg_catalog.$name;\n";
234 $sql .= "CREATE DEFAULT CONVERSION pg_catalog.$name FOR '$se' TO '$de' FROM $func;\n";
235 $sql .= "COMMENT ON CONVERSION pg_catalog.$name IS 'conversion for $se to $de';\n";
237 open($F,">$target/share/conversion_create.sql")
238 || die "Could not write to conversion_create.sql\n";
244 sub GenerateTimezoneFiles
248 my $mf = read_file("src/timezone/Makefile");
249 $mf =~ s{\\\s*[\r\n]+}{}mg;
250 $mf =~ /^TZDATA\s*:?=\s*(.*)$/m || die "Could not find TZDATA row in timezone makefile\n";
251 my @tzfiles = split /\s+/,$1;
253 print "Generating timezone files...";
255 "$conf\\zic\\zic -d \"$target/share/timezone\" " . join(" src/timezone/data/", @tzfiles));
259 sub GenerateTsearchFiles
263 print "Generating tsearch script...";
265 my $tmpl = read_file('src/backend/snowball/snowball.sql.in');
266 my $mf = read_file('src/backend/snowball/Makefile');
267 $mf =~ s{\\\s*[\r\n]+}{}mg;
268 $mf =~ /^LANGUAGES\s*=\s*(.*)$/m
269 || die "Could not find LANGUAGES line in snowball Makefile\n";
270 my @pieces = split /\s+/,$1;
271 open($F,">$target/share/snowball_create.sql")
272 || die "Could not write snowball_create.sql";
273 print $F read_file('src/backend/snowball/snowball_func.sql.in');
277 my $lang = shift @pieces || last;
278 my $asclang = shift @pieces || last;
282 if (-s "src/backend/snowball/stopwords/$lang.stop")
284 $stop = ", StopWords=$lang";
287 $txt =~ s#_LANGNAME_#${lang}#gs;
288 $txt =~ s#_DICTNAME_#${lang}_stem#gs;
289 $txt =~ s#_CFGNAME_#${lang}#gs;
290 $txt =~ s#_ASCDICTNAME_#${asclang}_stem#gs;
291 $txt =~ s#_NONASCDICTNAME_#${lang}_stem#gs;
292 $txt =~ s#_STOPWORDS_#$stop#gs;
305 print "Copying contrib data files...";
307 opendir($D, 'contrib') || croak "Could not opendir on contrib!\n";
308 while (my $d = readdir($D))
310 next if ($d =~ /^\./);
311 next unless (-f "contrib/$d/Makefile");
312 next if ($d eq "uuid-ossp"&& !defined($config->{uuid}));
313 next if ($d eq "sslinfo" && !defined($config->{openssl}));
314 next if ($d eq "xml2" && !defined($config->{xml}));
316 my $mf = read_file("contrib/$d/Makefile");
317 $mf =~ s{\\s*[\r\n]+}{}mg;
319 if ($mf =~ /^DATA_built\s*=\s*(.*)$/m) {$flist .= $1}
320 if ($mf =~ /^DATA\s*=\s*(.*)$/m) {$flist .= " $1"}
321 $flist =~ s/^\s*//; # Remove leading spaces if we had only DATA_built
325 $flist = ParseAndCleanRule($flist, $mf);
327 # Special case for contrib/spi
328 $flist = "autoinc.sql insert_username.sql moddatetime.sql refint.sql timetravel.sql"
330 foreach my $f (split /\s+/,$flist)
332 lcopy('contrib/' . $d . '/' . $f,$target . '/share/contrib/' . basename($f))
333 || croak("Could not copy file $f in contrib $d");
339 if ($mf =~ /^DATA_TSEARCH\s*=\s*(.*)$/m) {$flist .= $1}
342 $flist = ParseAndCleanRule($flist, $mf);
344 foreach my $f (split /\s+/,$flist)
346 lcopy('contrib/' . $d . '/' . $f,$target . '/share/tsearch_data/' . basename($f))
347 || croak("Could not copy file $f in contrib $d");
353 if ($mf =~ /^DOCS\s*=\s*(.*)$/mg) {$flist .= $1}
356 $flist = ParseAndCleanRule($flist, $mf);
358 # Special case for contrib/spi
360 "autoinc.example insert_username.example moddatetime.example refint.example timetravel.example"
362 foreach my $f (split /\s+/,$flist)
364 lcopy('contrib/' . $d . '/' . $f, $target . '/doc/contrib/' . $f)
365 || croak("Could not copy file $f in contrib $d");
374 sub ParseAndCleanRule
379 # Strip out $(addsuffix) rules
380 if (index($flist, '$(addsuffix ') >= 0)
384 for ($i = index($flist, '$(addsuffix ') + 12; $i < length($flist); $i++)
386 $pcount++ if (substr($flist, $i, 1) eq '(');
387 $pcount-- if (substr($flist, $i, 1) eq ')');
388 last if ($pcount < 0);
390 $flist = substr($flist, 0, index($flist, '$(addsuffix ')) . substr($flist, $i+1);
399 EnsureDirectories($target, 'include', 'include/libpq','include/internal',
400 'include/internal/libpq','include/server');
404 $target . '/include/',
405 'src/include/', 'postgres_ext.h', 'pg_config.h', 'pg_config_os.h', 'pg_config_manual.h'
407 lcopy('src/include/libpq/libpq-fs.h', $target . '/include/libpq/')
408 || croak 'Could not copy libpq-fs.h';
412 $target . '/include/',
413 'src/interfaces/libpq/','libpq-fe.h', 'libpq-events.h'
416 'Libpq internal headers',
417 $target .'/include/internal/',
418 'src/interfaces/libpq/', 'libpq-int.h', 'pqexpbuffer.h'
423 $target . '/include/internal/',
424 'src/include/', 'c.h', 'port.h', 'postgres_fe.h'
426 lcopy('src/include/libpq/pqcomm.h', $target . '/include/internal/libpq/')
427 || croak 'Could not copy pqcomm.h';
431 $target . '/include/server/',
432 'src/include/', 'pg_config.h', 'pg_config_os.h'
434 CopySetOfFiles('',[ glob("src\\include\\*.h") ],$target . '/include/server/');
436 opendir($D, 'src/include') || croak "Could not opendir on src/include!\n";
438 while (my $d = readdir($D))
440 next if ($d =~ /^\./);
441 next if ($d eq '.git');
442 next if ($d eq 'CVS');
443 next unless (-d 'src/include/' . $d);
445 EnsureDirectories($target . '/include/server', $d);
446 system("xcopy /s /i /q /r /y src\\include\\$d\\*.h \"$target\\include\\server\\$d\\\"")
447 && croak("Failed to copy include directory $d\n");
451 my $mf = read_file('src/interfaces/ecpg/include/Makefile');
452 $mf =~ s{\\s*[\r\n]+}{}mg;
453 $mf =~ /^ecpg_headers\s*=\s*(.*)$/m || croak "Could not find ecpg_headers line\n";
456 $target . '/include/',
457 'src/interfaces/ecpg/include/',
458 'ecpg_config.h', split /\s+/,$1
460 $mf =~ /^informix_headers\s*=\s*(.*)$/m || croak "Could not find informix_headers line\n";
461 EnsureDirectories($target . '/include', 'informix', 'informix/esql');
463 'ECPG informix headers',
464 $target .'/include/informix/esql/',
465 'src/interfaces/ecpg/include/',
474 my $majorver = shift;
476 print "Installing NLS files...";
477 EnsureDirectories($target, "share/locale");
483 &&!push(@flist, $File::Find::name);
490 my $prgm = DetermineCatalogName($_);
493 next unless ($dir =~ /([^\/]+)\/po$/);
494 foreach (glob("$dir/*.po"))
497 next unless /([^\/]+)\.po/;
500 EnsureDirectories($target, "share/locale/$lang", "share/locale/$lang/LC_MESSAGES");
502 "\"$nlspath\\bin\\msgfmt\" -o \"$target\\share\\locale\\$lang\\LC_MESSAGES\\$prgm-$majorver.mo\" $_"
503 )&& croak("Could not run msgfmt on $dir\\$_");
510 sub DetermineMajorVersion
512 my $f = read_file('src/include/pg_config.h') || croak 'Could not open pg_config.h';
513 $f =~ /^#define\s+PG_MAJORVERSION\s+"([^"]+)"/m || croak 'Could not determine major version';
517 sub DetermineCatalogName
519 my $filename = shift;
521 my $f = read_file($filename) || croak "Could not open $filename";
522 $f =~ /CATALOG_NAME\s*\:?=\s*(\S+)/m || croak "Could not determine catalog name in $filename";
528 my $filename = shift;
533 open($F, $filename) || die "Could not open file $filename\n";