Browse files

Move to a Perl-based build wrapper

  • Loading branch information...
1 parent 8590469 commit 12b852eccafa1e5e14fd5540d871ea34d9b45447 @ringerc ringerc committed Jan 5, 2013
Showing with 587 additions and 196 deletions.
  1. +1 −0 .gitignore
  2. +11 −13 Makefile
  3. +212 −0 PgBuildWin/Config.pm
  4. +56 −0 PgBuildWin/DetectSDK.pm
  5. +66 −0 PgBuildWin/PgBuildWin.pm
  6. +176 −49 README.txt → README.md
  7. +16 −0 buildcwd.pl
  8. +13 −0 buildgit.pl
  9. +0 −96 settings-defaults.mak
  10. +0 −38 settings-template.mak
  11. +36 −0 settings_template.pl
View
1 .gitignore
@@ -1,2 +1,3 @@
.*.swp
settings.mak
+settings.pl
View
24 Makefile
@@ -5,28 +5,26 @@
# http://msdn.microsoft.com/en-us/library/y5d8s7f6(v=vs.80).aspx
# http://msdn.microsoft.com/en-us/library/7y32zxwh(v=vs.80).aspx
-!INCLUDE settings.mak
-!INCLUDE settings-defaults.mak
-
!IFNDEF TARGET_CPU
-!ERROR "TARGET_CPU is not set. Did you run vcvars or setenv?"
+!ERROR "TARGET_CPU is not set. See the README."
!ENDIF
!IFNDEF CONFIGURATION
-!ERROR "CONFIGURATION is not set. Did you run vcvars or setenv?"
+!ERROR "CONFIGURATION is not set. See the README."
!ENDIF
-!IFNDEF PLATFORMTOOLSET
-!ERROR "PLATFORMTOOLSET is not set. Did you run vcvars or setenv?"
+!IFNDEF SDKVERSION
+!ERROR "SDKVERSION is unset. You need to invoke this makefile via buildall.pl, not directly."
!ENDIF
-# PLATFORMTOOLSET, TARGET_CPU and CONFIGURATION are set by vcvars from visual studio
-# or setenv from the winsdk for WinSDK pass /x86 or /x64 to set TARGET_CPU
-# and /Release or /Debug to set CONFIGURATION
+# TARGET_CPU and CONFIGURATION are set by setenv from the winsdk.
+# Pass /x86 or /x64 to set TARGET_CPU and /Release or /Debug to set CONFIGURATION .
#
-# You can't set PLATFORMTOOLSET, it's a version param.
+# These vars are not set by vcvarsall.bat. You must set CONFIGURATION, TARGET_CPU and
+# PLATFORMTOOLSET on the nmake command line or in the environment. PLATFORMTOOLSET
+# is rather under-documented;
#
-LIBBUILDDIR=$(LIBDIR)\$(PLATFORMTOOLSET)\$(TARGET_CPU)\$(CONFIGURATION)
+LIBBUILDDIR=$(LIBDIR)\$(SDKVERSION)\$(TARGET_CPU)\$(CONFIGURATION)
# By default the tools will build PostgreSQL from git in a tree it creates.
# If you want to you can instead specify a PGBUILDDIR location, in which case
@@ -35,7 +33,7 @@ LIBBUILDDIR=$(LIBDIR)\$(PLATFORMTOOLSET)\$(TARGET_CPU)\$(CONFIGURATION)
#
!IFDEF USE_GIT
-PGBUILDDIR=$(PGDIR)\$(PLATFORMTOOLSET)\$(TARGET_PLATFORM)\$(TARGET_CPU)\$(CONFIGURATION)\$(PG_BRANCH)
+PGBUILDDIR=$(PGDIR)\$(SDKVERSION)\$(TARGET_PLATFORM)\$(TARGET_CPU)\$(CONFIGURATION)\$(PG_BRANCH)
!ELSE
!IFNDEF PGBUILDDIR
!ERROR USE_GIT is not set, so you must set PGBUILDDIR to the location of a PostgreSQL source tree
View
212 PgBuildWin/Config.pm
@@ -0,0 +1,212 @@
+package PgBuildWin::Config;
+
+use strict;
+use warnings;
+use Exporter;
+use File::Spec::Functions qw/catfile catdir devnull/;
+use IPC::Open3 qw( open3 );
+use FindBin qw($Bin);
+
+our $VERSION = 1.00;
+our @ISA = qw(Exporter);
+# Always export:
+our @EXPORT = ();
+# Export only on request
+our @EXPORT_OK = qw(cfg_read);
+
+
+sub set_ind($$$) {
+ # Set key $k in hash of hash-ref $h to $v if $k is not already set
+ # to a non-undef value.
+ my ($h, $k, $v) = @_;
+ if (!defined($h->{$k})) {
+ $h->{$k} = $v;
+ }
+};
+
+sub test_cmd($) {
+ my $cmd = $_[0];
+ open(local *NUL, '>', devnull()) or die;
+ my $pid = open3('<STDIN', '>&NUL', '>&NUL', $cmd);
+ waitpid($pid, 0);
+ return $? == 0;
+}
+
+sub test_lang($$$$) {
+ # Common code from test_perl, test_python, etc
+ my ($ma, $k, $default, $testcmd) = ($_[0], $_[1], $_[2], $_[3]);
+ my $cmddir = exists $ma->{$k} ? $ma->{$k} : $default;
+ if (!defined($cmddir)) {
+ # cmd explicitly set to `undef`; return
+ return 0;
+ }
+ $testcmd =~ s/\{COMMANDDIR\}/$cmddir/;
+ my $cmdok = test_cmd($testcmd);
+ if ($cmdok) {
+ print("Found $k at $cmddir\n");
+ $ma->{$k} = $cmddir;
+ } else {
+ print("config.pl makeargs $k: $testcmd failed\n");
+ print("Disabling $k. To suppress this message set $k=undef in settings.pl.\n");
+ delete($ma->{$k});
+ }
+ return $cmdok;
+}
+
+sub test_perl($$$) {
+ return test_lang($_[0], $_[1], $_[2], catdir('"{COMMANDDIR}"','bin','perl.exe') . ' --version');
+}
+
+sub test_python($$$) {
+ return test_lang($_[0], $_[1], $_[2], catdir('"{COMMANDDIR}"','python.exe') . ' --version');
+}
+
+sub test_tcl($$$) {
+ # TCL is weird. It doesn't have any sane way to just pass an argument to see if it
+ # exists and works. You have to use 'echo exit 0 | d:\Tcl_x64\bin\tclsh.exe' or similar.
+ #
+ return test_lang($_[0], $_[1], $_[2], 'echo exit 0 | "{COMMANDDIR}"\bin\tclsh.exe');
+ exit(0);
+}
+
+sub find_git() {
+ my $git;
+ foreach $git (
+ "git",
+ "$ENV{'ProgramFiles'}\\Git\\bin\\git",
+ "$ENV{'ProgramFiles(x86)'}\\Git\\bin\\git"
+ ) {
+ return $git if test_cmd('"' . $git . '" --version');
+ }
+ return;
+}
+
+# Pass a reference to the config hash to merge_defaults
+# and it'll be extended with default settings.
+sub merge_defaults($$) {
+ my ($cfg, $use_git) = ($_[0], $_[1]);
+
+ die("makeargs key missing from cfg dict")
+ unless defined($cfg->{'makeargs'});
+ my $ma = $cfg->{'makeargs'};
+
+ set_ind($ma, 'TARGET_CPU', $ENV{'TARGET_CPU'});
+ my $cpu = lc($ma->{'TARGET_CPU'});
+ if (!defined($cpu)) {
+ die("TARGET_CPU isn't defined in settings.pl or the environment. Did you run vcvars or setenv.cmd?");
+ }
+
+ die("Don't set USE_GIT in settings.pl; use buildgit.pl instead.") if exists($ma->{'USE_GIT'});
+
+ set_ind($ma, 'CONFIGURATION', $ENV{'CONFIGURATION'});
+
+ set_ind($ma, 'LIBDIR', '\pg\libs');
+ set_ind($ma, 'PKGDIR', catdir($ma->{'LIBDIR'}, 'pkgs'));
+ if (defined($ma->{'USE_GIT'})) {
+ die("Don't set USE_GIT in settings.pl; use buildgit.pl instead");
+ }
+ if ($use_git) {
+ if (!defined($ma->{'GIT'})) {
+ # Git location not specified. Try to find it; if we can't,
+ # fail.
+ $ma->{'GIT'} = find_git()
+ or die ("If USE_GIT is set you must set GIT to the location of the git executable or add git to the PATH");
+ }
+ } else {
+ # Unset git-related params if USE_GIT is not set
+ delete $ma->{'GIT'};
+ delete $ma->{'GIT_PULL'};
+ delete $ma->{'PG_GIT_URL'};
+ delete $ma->{'PGDIR'};
+ delete $ma->{'PG_BRANCH'};
+ }
+ set_ind($ma, 'TOOLPREFIX', 'c:');
+ # TODO: Be smarter about these, try to find them
+ # in the Registry?
+ # These will be the paths you get if you installed
+ # with the recommended unattended install settings.
+ if ($cpu eq "x86") {
+ test_perl($ma, 'PERL_X86', catdir($ma->{'TOOLPREFIX'}, 'perl'));
+ test_python($ma, 'PYTHON2_X86', catdir($ma->{'TOOLPREFIX'}, 'Python27_x86'));
+ test_python($ma, 'PYTHON3_X86', catdir($ma->{'TOOLPREFIX'}, 'Python33_x86'));
+ test_tcl($ma, 'TCL_X86', catdir($ma->{'TOOLPREFIX'}, 'Tcl_85_x86'));
+ } elsif ($cpu eq "x64") {
+ test_perl($ma, 'PERL_X64', catdir($ma->{'TOOLPREFIX'}, 'perl64'));
+ test_python($ma, 'PYTHON2_X64', catdir($ma->{'TOOLPREFIX'}, 'Python27_x64'));
+ test_python($ma, 'PYTHON3_X64', catdir($ma->{'TOOLPREFIX'}, 'Python33_x64'));
+ test_tcl($ma, 'TCL_X64', catdir($ma->{'TOOLPREFIX'}, 'Tcl_85_x64'));
+ } else {
+ die("Unknown TARGET_CPU $cpu");
+ }
+
+ set_ind($ma, 'MINGW', catdir($ma->{'TOOLPREFIX'}, 'MinGW'));
+ set_ind($ma, 'MSYS', catdir($ma->{'MINGW'}, 'msys', '1.0'));
+ # you can also use 7za, the standalone 7zip, here.
+ set_ind($ma, '7ZIP', catfile($ENV{'ProgramFiles'}, '7-Zip','7z.exe'));
+
+ # Tools the scripts can download and install
+ # for you.
+ set_ind($ma, 'ZLIB_URL', 'http://zlib.net/zlib127.zip');
+ set_ind($ma, 'ZLIB_VERSION', '1.2.7');
+
+ # Override this to specify a particular perl executable
+ set_ind($ma, 'PERL_CMD', 'perl');
+
+ # Where to find wget for downloading sources
+ # TODO: Do downloads with Perl instead
+ set_ind($ma, 'WGET', catfile($ma->{'MSYS'}, 'bin', 'wget.exe'));
+
+ # FIXME: currently we don't respect $(FLEX) and $(BISON)
+ # We assume they're in the msys directory.
+ set_ind($ma, 'FLEX', catfile($ma->{'MSYS'}, 'bin', 'flex.exe'));
+ set_ind($ma, 'BISON', catfile($ma->{'MSYS'}, 'bin', 'bison.exe'));
+ set_ind($ma, 'TOUCH', catfile($ma->{'MSYS'}, 'bin', 'touch.exe'));
+};
+
+
+# Read a filenamed "settings.pl" in the same location
+# as the outer script, merge it with the defaults, and
+# return it.
+#
+# Usage: cfg_read_file(path_to_settings_pl, use_git)
+#
+sub cfg_read_file($$) {
+ my ($settingspl, $use_git) = ($_[0], $_[1]);
+ {
+ package PgBuildWin::CFG;
+ my $return;
+ our $cfg;
+ unless ($return = do $settingspl) {
+ die "couldn't parse $settingspl: $@" if $@;
+ die "couldn't do $settingspl: $!" unless defined $return;
+ die "$settingspl ran with errors" unless $return;
+ }
+ }
+ if (!defined($PgBuildWin::CFG::cfg)) {
+ die("settings.pl must assign a hash to \$cfg, but did not");
+ }
+ merge_defaults($PgBuildWin::CFG::cfg, $use_git);
+ return $PgBuildWin::CFG::cfg;
+};
+
+# Usage: cfg_read(use_git)
+#
+sub cfg_read($) {
+ my $use_git = $_[0];
+ my $pg_build_win_dir = $Bin;
+ my $settingspl = catfile( ($pg_build_win_dir), 'settings.pl');
+ if (! -e $settingspl) {
+ print "Expected to find settings.pl at $settingspl.\n";
+ print "Copy settings_template.pl to $settingspl and edit to fit your environment.\n";
+ die("Exiting: settings.pl missing");
+ }
+ my $cfg = cfg_read_file($settingspl, $use_git);
+ $cfg->{'makefile'} = catfile($pg_build_win_dir, 'Makefile');
+ return $cfg;
+}
+
+1;
+
+
+
+
View
56 PgBuildWin/DetectSDK.pm
@@ -0,0 +1,56 @@
+package PgBuildWin::DetectSDK;
+
+use strict;
+
+our $VERSION = 1.00;
+our @ISA = qw(Exporter);
+our @EXPORT = ();
+our @EXPORT_OK = qw/ver_string/;
+
+sub get_vc_info() {
+ # Extract the version from the WindowsSDKDir path; amazingly,
+ # there doesn't seem to be an environment variable or standard
+ # command to report the SDK version.
+ if (!defined($ENV{'WindowsSDKDir'})) {
+ die("WindowsSDKDir env var not set. Did you run setenv.cmd or vcvars.bat?");
+ }
+ my $sdkvers;
+ if ($ENV{'WindowsSDKDir'} =~ /Microsoft SDKs\\Windows\\([^\\]+)/) {
+ $sdkvers = $1;
+ }
+
+ # Try to determine the cl.exe version
+ open(CLOUTPUT, "cl 2>&1 |") or die ("Failed to exec cl.exe: $!");
+ my $clvers;
+ while (<CLOUTPUT>) {;
+ if (/.*Version\s(\d{1,3})/) {
+ $clvers = $1;
+ last;
+ }
+ }
+ close(CLOUTPUT);
+ if (!defined($clvers)) {
+ die("cl.exe executed, but unable to determine cl.exe version from output");
+ }
+
+ # If we're running under a Visual Studio SDK set up with vcvarsall.bat,
+ # VCINSTALLDIR will point to the Visual Studio install. Get its version.
+ my $vsvers;
+ if (defined($ENV{'VCINSTALLDIR'}) && $ENV{'VCINSTALLDIR'} =~ /Microsoft Visual Studio (\d+\.?\d*)/) {
+ $vsvers = $1;
+ }
+ return ($sdkvers, $clvers, $vsvers);
+}
+
+sub detect_sdk() {
+ our ($sdkvers, $clvers, $vsvers) = get_vc_info();
+ our $verstring = "sdk${sdkvers}_cl${clvers}" . (defined($vsvers)?"_vs${vsvers}":"");
+};
+
+sub ver_string() {
+ our $verstring;
+ if (!defined($verstring)) {
+ detect_sdk();
+ }
+ return $verstring;
+}
View
66 PgBuildWin/PgBuildWin.pm
@@ -0,0 +1,66 @@
+#!perl -w
+#
+# This script is a wrapper around the makefiles
+# used to do most of the work of building PostgreSQL and its
+# dependencies. The it works around some of the
+# limitations of nmake, like the lack of any way to define
+# a macro based on the output of invoking a command.
+#
+# A file named 'settings.pl' must be present in the same
+# directory as buildall.pl.
+#
+
+our $VERSION = 1.00;
+our @ISA = qw(Exporter);
+# Always export:
+our @EXPORT = ();
+# Export only on request
+our @EXPORT_OK = qw(build);
+
+use strict;
+use Data::Dumper;
+use Cwd;
+use File::Spec::Win32 qw(canonpath);
+
+use PgBuildWin::Config qw(cfg_read);
+use PgBuildWin::DetectSDK;
+
+sub build($) {
+ my ($use_git) = @_;
+
+ my $verstring = PgBuildWin::DetectSDK->ver_string();
+ my $cfg = cfg_read($use_git);
+ print "Effective configuration:\n";
+ print Dumper($cfg) . "\n\n";
+
+ my @makeargs = (
+ '/F', "\"$cfg->{'makefile'}\"",
+ "SDKVERSION=\"$verstring\""
+ );
+ if ($use_git) {
+ push(@makeargs, 'USE_GIT=1');
+ } else {
+ push(@makeargs, 'PGBUILDDIR="' . File::Spec::Win32->canonpath(getcwd()) . '"');
+ }
+ # Add config make arguments
+ while (my ($k,$v) = each %$cfg->{'makeargs'}) {
+ if (defined($v)) {
+ push(@makeargs, "$k=\"$v\"");
+ }
+ }
+ # Add command line args. Should really clean this up.
+ foreach my $arg (@ARGV) {
+ print("ARG: $arg\n");
+ push(@makeargs, '"'.$arg.'"');
+ }
+ my $cmd = "nmake ".join(' ',@makeargs);
+ print "Make command:\n";
+ print $cmd . "\n";
+ my $ret = system($cmd);
+ if ($ret != 0) {
+ print("Build failed, return code from nmake was $ret\n");
+ } else {
+ print("Build successful");
+ }
+ return $ret == 0;
+}
View
225 README.txt → README.md
@@ -1,14 +1,18 @@
These scripts create a PostgreSQL build environment for Windows, and build
PostgreSQL.
-They're for NMake, the Microsoft version of make that uses cmd.exe. It comes
-with Visual Studio. Yes, that's horrid, but it's better than trying to disentangle
-the environment of mingw from that of Visual Studio.
+The scripts use Perl as a wrapper around Microsoft's nmake, the build tool
+that comes with the Microsoft Windows SDK and with Visual Studio.
-You will require installs of ActiveState Perl, ActiveState TCL, Python.org
+You will need installs of ActiveState Perl, ActiveState TCL, Python.org
Python 2, MinGW, git (from git-scm.org), and the Microsoft SDK 7.1 to use these
-scripts. Instructions on unattended installs for these tools are coming shortly;
-just need to copy them from another machine.
+scripts. If you want to use a different Windows SDK, see "Other SDKs".
+
+I recommend that you avoid running these scripts on a machine you use to
+run a real PostgreSQL instance you care about. These scripts won't break
+anything (that I'm aware of), but on Windows it's generally risky to do dev
+work on a production machine. As always, keep good backups and make a restore
+point before proceeding.
Download Windows SDK 7.1
========================
@@ -40,20 +44,26 @@ and scripts are NOT TESTED on 32-bit windows, only on 64-bit Windows 7 and Windo
Download:
-* ActiveState TCL x64 and x86 from http://www.activestate.com/activetcl/downloads
* ActiveState Perl x86 and x64 from http://www.activestate.com/activeperl/downloads
-* Python.org python 2.7 and 3.3, both in x86 and x64 versions from http://python.org
+ (Perl is not an optional dependency, it's required to run these build scripts and
+ the PostgreSQL Windows build infrastructure).
* mingw-get-inst from http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/
* git from http://git-scm.com/download/win
* 7-zip from http://www.7-zip.org/download.html
+... and optionally:
+
+* ActiveState TCL x64 and x86 from http://www.activestate.com/activetcl/downloads
+* Python.org python 2.7 and 3.3, both in x86 and x64 versions from http://python.org
+
You need MinGW even for MSVC builds because you need the "flex" executable
from it to build on x64; the version provided on the PostgreSQL site doesn't
run on win64. These scripts also use bison, wget and touch from mingw. All
these tools come with msysgit too, so a future version may support using
msysgit instead of MinGW.
I also recommend:
+
* notepad++ from http://http://notepad-plus-plus.org/download/
Install the tools
@@ -77,13 +87,15 @@ version.
start /wait Git-1.8.0-preview20121022.exe /silent
start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x64-296175.msi /qb /passive PERL_PATH=Yes PERL_EXT=Yes
start /wait msiexec /i ActivePerl-5.16.1.1601-MSWin32-x86-296175.msi /qb /passive PERL_PATH=No PERL_EXT=No
- start /wait ActiveTcl8.5.12.0.296033-win32-ix86-threaded.exe --directory %SystemDrive%\TCL_85_x86
- start /wait ActiveTcl8.5.12.0.296033-win32-x86_64-threaded.exe --directory %SystemDrive%\TCL_85_x64
start /wait msiexec /i python-2.7.3.amd64.msi /qb /passive TARGETDIR=%SystemDrive%\Python27_x64 ALLUSERS=1
start /wait msiexec /i python-2.7.3.msi /qb /passive TARGETDIR=%SystemDrive%\Python27_x86 ALLUSERS=1
start /wait msiexec /i python-3.3.0.amd64.msi /qb /passive TARGETDIR=%SystemDrive%\Python33_x64 ALLUSERS=1
start /wait msiexec /i python-3.3.0.msi /qb /passive TARGETDIR=%SystemDrive%\Python33_x64 ALLUSERS=1
+Now install TCL if you want it. These installers don't run fully unattended.
+ start /wait ActiveTcl8.5.*-win32-ix86-threaded.exe --directory %SystemDrive%\TCL_85_x86
+ start /wait ActiveTcl8.5.*-win32-x86_64-threaded.exe --directory %SystemDrive%\TCL_85_x64
+
If you downloaded the offline install ISO for the Windows SDK, you can install it with:
"%PROGRAMFILES%\7-Zip\7z.exe" x -owinsdk GRMSDKX_EN_DVD.iso
@@ -100,10 +112,20 @@ Optionally also install notepad++:
Configure the build
===================
-Copy settings-template.mak to settings.mak and edit it to reflect your
+Copy settings_template.pl to settings.pl and edit it to reflect your
environment. You can pass the settings on the command line instead, but
-currently an empty settings.mak is still required. See settings-defaults.mak
-for what you can override.
+currently an empty settings.pl is still required.
+
+Settings on the command line are passed as nmake variables, eg:
+
+ SETTING="the value"
+
+and in config.pl as Perl hashmap entries, eg:
+
+ 'SETTING' => 'the value',
+
+To see what you can override, see the settings summary printed when you run
+buildcwd.pl / buildgit.pl, or examine PgBuildWin\Config.pm .
There are two build modes offered; you must pick whether you want the build
scripts to manage the PostgreSQL sources trees for you by checking them out
@@ -115,26 +137,26 @@ the dependencies that the build scripts manage for you, eg:
LIBDIR=\where\to\put\libraries
-Anything inside LIBDIR will be deleted by "nmake really-clean"
+Anything inside LIBDIR will be deleted by "build{git|cwd}.pl really-clean"
-Automatic PostgreSQL source trees - USE_GIT
--------------------------------------------
+Automatic PostgreSQL source trees - buildgit.pl
+-----------------------------------------------
-If you set USE_GIT and specify where to put the source trees (PGDIR), where to
+If you use buildgit.pl specify where to put the source trees (PGDIR), where to
find a PostgreSQL git mirror (PG_GIT_URL), what branch to check out (PG_BRANCH)
-and the location of the git executable (GIT), the build scripts will manage
-your builds for you under PGDIR. Eg:
+and optionally the location of the git executable (GIT), the build scripts will
+manage your builds for you under PGDIR. Eg, in settings.pl:
- USE_GIT=1
- GIT=c:\Program Files (x86)\Git\bin\git.exe
- PGDIR=c:\postgresql-build
- PG_GIT_URL=c:\postgresql-git-bare-mirror
- PG_BRANCH=master
+ 'GIT' => 'c:\Program Files (x86)\Git\bin\git.exe',
+ 'PGDIR' => 'c:\postgresql-build',
+ 'PG_GIT_URL' => 'c:\postgresql-git-bare-mirror',
+ 'PG_BRANCH' => 'master'
-Anything inside PGDIR will be deleted by "nmake really-clean". The source tree will be
-reset using "git clean -fdx" when you "nmake clean" or "nmake postgresql-clean", so don't
-do work in the script-managed PostgreSQL trees; either push to a branch and have the tools
-build the branch, or manually manage the source tree (see below).
+Anything inside PGDIR will be deleted by "buildgit.pl really-clean". The source
+tree will be reset using "git clean -fdx" when you "buildgit.pl clean" or
+"buildgit.pl postgresql-clean", so don't do work in the script-managed
+PostgreSQL trees; either push to a branch and have the tools build the branch,
+or manually manage the source tree (see below).
Builds and installs will go in different locations (PGBUILDDIR) based on their settings
- /x86 vs /x64, /release vs /debug, SDK version, target OS, and Pg branch. For example,
@@ -146,11 +168,11 @@ set to c:\postgresql-build will go in:
As cloning Pg from scratch takes time and bandwidth, I recommend cloning a bare copy
of the Pg repo *outside* LIBDIR and PGDIR, eg:
- git clone --bare --mirror git://git.postgresql.org/git/postgresql.git d:\postgresql-git
+ git clone --bare --mirror git://git.postgresql.org/git/postgresql.git d:/postgresql-git
and specifying the path to it as PG_GIT_URL:
- PG_GIT_URL=d:\postgresql-git
+ 'PG_GIT_URL' => 'd:\postgresql-git'
To pull new changes into that repository use, "git fetch".
@@ -163,36 +185,34 @@ tools might be managing your git checkouts, or you could even be working from
source tarballs. In that case you won't want the build scripts messing around
with git.
-You can still use these scripts to manage your library dependencies and to
-generate buildenv.pl and config.pl for you if you're working in a manually
-managed source tree. Just leave USE_GIT unset, and set PGBUILDDIR to the
-location of your source tree.
-
-For example:
+buildcwd.pl will look for settings.pl in the current directory, then in the
+scripts directory. This means that it'll execute any "settings.pl" in the
+directory you invoke it in, so keep that in mind when running builds on
+untrusted branches.
- nmake /f d:\pg_build_win PGBUILDDIR=d:\my-postgresql-dev-tree
+Just cd to the source tree and invoke buildcwd.pl from there:
-The pseudo-env-var %CD% is useful if you want to build a PostgreSQL source tree
-rooted in the current directory.
+For example:
-If USE_GIT is not set, the scripts won't use git and you don't need it installed.
-In this mode, "nmake postgresql-clean" and "nmake clean" will use
-"src\tools\msvc\clean.bat dist" to clean the source tree, rather than using git.
+ cd \path\to\pg_source_tree
+ \path\to\pg_build_win\buildcwd.pl
-You still need a settings.mak, but if you set LIBDIR on the command line then it
-can be an empty file.
+If using buildcwd.pl, the scripts won't use git and you don't need it
+installed. In this mode, "buildcwd.pl postgresql-clean" and "buildcwd.pl
+clean" will use "src\tools\msvc\clean.bat dist" to clean the source tree,
+rather than using git.
(Optional) Download library source archives
===========================================
-The build tools will use wget to download the source archives into LIBDIR\pkg
-for you if it can't find them.
+The build tools will download the source archives into LIBDIR\pkg for you if it
+can't find them.
If you like, you can create LIBDIR\pkg and copy the source archives from
somewhere yourself for offline use. The filenames the build scripts look
for are specified in settings-default.mak and can be overridden in settings.mak.
-Be warned that "nmake really-clean" will delete LIBDIR and its contents,
+Be warned that "build{cwd|git}.pl really-clean" will delete LIBDIR and its contents,
including any source packages you put there.
SET UP VISUAL STUDIO ENVIRONMENT
@@ -218,9 +238,14 @@ BUILD
=====
In a command prompt that's had its environment set up as per "SET UP
-VISUAL STUDIO ENVIRONMENT", do a full build with:
+VISUAL STUDIO ENVIRONMENT", do a full build using:
- nmake /f pg_build_win\Makefile postgresql
+ cd \some\postgresql\sources\
+ \path\to\pg_build_win\buildcwd.pl postgresql
+
+or to use automatically managed git trees:
+
+ buildgit.pl postgresql
Supported targets are:
@@ -261,6 +286,108 @@ CLEANING:
* clean - remove built libraries and clean PostgreSQL working tree
* really-clean: Remove built libraries and downloaded files, delete PostgreSQL checkout and working tree
+TROUBLESHOOTING
+===============
+
+SDK 7.1 / Visual Studio 2010 conflict with Visual Studio 2012
+-------------------------------------------------------------
+
+If you have Visual Studio 2012 installed on your computer, Windows SDK
+7.1 may fail to compile programs with errors like:
+
+LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
+
+This is a known issue with Visual Studio 2010 that also appears to affect SDK 7.1, since
+the SDK uses the same compiler suite. The problem was fixed in Visual Studio 2010 SP1, but
+not in SDK 7.1. To work around the problem you must install Visual C++ Express Edition 2010
+and then the Visual Studio 2010 Service Pack 1 update.
+
+Permission denied errors when cleaning
+--------------------------------------
+
+Unlike POSIX systems, on Windows a file or folder that is open by a program cannot
+be deleted or renamed.
+
+If you've run regression tests and they've crashed out without properly terminating
+the server they've started, you will find that you can't clean your working directory
+and you'll get "permission denied" errors for files/folders you obviously do have full
+ownership and control of.
+
+Open up Process Explorer (preferered) or Task Manager. Now find and terminate the problem
+processes - look for psql.exe, pg_regress.exe and postgres.exe . If you have a real PostgreSQL
+instance you use for real work on this machine, be careful not to terminate it.
+
+
+Other SDKs
+==========
+
+Test reports for SDKs and Visual Studio versions listed as "untested"
+below would be greatly appreciated, particularly if they come with
+patches fixing any issues encountered. Add a GitHub issue with the results,
+or better, send a pull request with a docs patch.
+
+Visual Studio 6 is not and will never be supported.
+
+Visual Studio 8 (2005)
+------------------
+Untested.
+
+Visual Studio 9 (2008)
+------------------
+Untested.
+
+Environment setup with vcvarsall.bat:
+
+ "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" /?
+
+Visual Studio 10 (2010)
+------------------
+Visual Studio 2010 and its express edition should work fine with no changes. Environment setup with vcvarsall.bat.
+
+ "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" /?
+
+vcvarsall.bat does not set TARGET_CPU, CONFIGURATION or PLATFORMTOOLSET so you must set these environment variables yourself.
+
+Visual Studio 11 (2012)
+------------------
+Installing Visual Studio 2012 breaks Visual Studio 2010 (pre-SP1) and Windows SDK 7.1 . See TROUBLESHOOTING.
+
+Environment setup with vcvarsall.bat or VsDevCmd.bat:
+
+ "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" /?
+ "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat"
+
+Untested.
+
+Microsoft Platform SDK for Windows XP SP2
+-----------------------------------------
+Untested
+
+Microsoft Windows SDK for Windows 7 and .NET Framework 4 (7.1)
+--------------------------------------------------------------
+Known working, recommended. Environment setup with setenv.cmd.
+
+ "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /?
+
+Microsoft Windows SDK for Windows 8 and .NET Framework 4.5 (v8.0a)
+------------------------------------------------------------------
+Untested.
+
+Obsolete versions
+-----------------
+
+The following obsolete SDK and Visual Studio releases are not supported and will never be supported by pg_build_win. Patches adding support will be rejected.
+
+* Visual Studio 97
+* Visual Studio 6
+* Visual Studio 7 (.NET 2002, 2003)
+* All Microsoft Platform SDK releases prior to Microsoft Platform SDK for Windows XP SP2
+
+Unlisted SDKs
+-------------
+
+If you have test results for an SDK not listed above, please add a GitHub issue with the results.
+
RELEVANT DOCUMENTATION
======================
View
16 buildcwd.pl
@@ -0,0 +1,16 @@
+#!perl -w
+#
+use FindBin qw($Bin);
+use lib "$Bin";
+use PgBuildWin::PgBuildWin qw(build);
+
+my $val;
+foreach $val (@ARGV) {
+ if ($val =~ /^"?USE_GIT/) {
+ die("Don't pass USE_GIT on the command line. Use buildgit.pl instead.");
+ }
+}
+if (! -e 'src\tools\msvc\build.pl') {
+ die('src\tools\msvc\build.pl not found - did you run buildcwd.pl from a PostgreSQL source tree? See the README.');
+}
+build(0);
View
13 buildgit.pl
@@ -0,0 +1,13 @@
+#!perl -w
+#
+use FindBin qw($Bin);
+use lib "$Bin";
+use PgBuildWin::PgBuildWin qw(build);
+
+my $val;
+foreach $val (@ARGV) {
+ if ($val =~ /^"?USE_GIT/) {
+ die("Don't pass USE_GIT on the command line. Use buildgit.pl instead.");
+ }
+}
+build(1);
View
96 settings-defaults.mak
@@ -1,96 +0,0 @@
-#
-# Command and tool locations, working directories, etc.
-#
-
-# Working directory locations
-!IFNDEF LIBDIR
-LIBDIR=\pg\libs
-!ENDIF
-!IFNDEF PKGDIR
-PKGDIR=$(LIBDIR)\pkg
-!ENDIF
-
-# These settings only apply if USE_GIT is set
-!IFDEF USE_GIT
-
-!IFNDEF PG_GIT_URL
-!ERROR If USE_GIT is set, you must set PG_GIT_URL so we know where to get sources from. See the README.
-!ENDIF
-!IFNDEF PGDIR
-!ERROR If USE_GIT is set you must specify PGDIR as the root of a tree to put builds in
-!ENDIF
-!IFNDEF PG_BRANCH
-!ERROR If USE_GIT is set you must specify PG_BRANCH so we know what to check out
-!ENDIF
-!IFNDEF GIT
-!ERROR If USE_GIT is set you must set GIT to the location of the git executable, or "git" if it's on the PATH
-!ENDIF
-
-!ENDIF
-
-
-!IFNDEF TOOLPREFIX
-TOOLPREFIX=c:
-!ENDIF
-
-
-# These will be the paths you get if you installed
-# with the recommended unattended install settings.
-!IFNDEF PERL_X86
-PERL_X86=$(TOOLPREFIX)\perl
-!ENDIF
-!IFNDEF PERL_X64
-PERL_X64=$(TOOLPREFIX)\perl64
-!ENDIF
-!IFNDEF PYTHON2_X86
-PYTHON2_X86=$(TOOLPREFIX)\Python27_x86
-!ENDIF
-!IFNDEF PYTHON2_X64
-PYTHON2_X64=$(TOOLPREFIX)\Python27_x64
-!ENDIF
-!IFNDEF PYTHON3_X86
-PYTHON3_X86=$(TOOLPREFIX)\Python33_x86
-!ENDIF
-!IFNDEF PYTHON3_X64
-PYTHON3_X64=$(TOOLPREFIX)\Python33_x64
-!ENDIF
-!IFNDEF TCL_X86
-TCL_X86=$(TOOLPREFIX)\Tcl_85_x86
-!ENDIF
-!IFNDEF TCL_X64
-TCL_X64=$(TOOLPREFIX)\Tcl_85_x64
-!ENDIF
-
-!IFNDEF MINGW
-MINGW=$(TOOLPREFIX)\MinGW
-!ENDIF
-
-!IFNDEF MSYS
-MSYS=$(MINGW)\msys\1.0\
-!ENDIF
-
-!IFNDEF 7ZIP
-7ZIP=c:\Program Files\7-Zip\7z.exe
-!ENDIF
-
-# Tools the scripts can download and install
-# for you.
-!IFNDEF ZLIB_URL
-ZLIB_URL=http://zlib.net/zlib127.zip
-!ENDIF
-!IFNDEF ZLIB_VERSION
-ZLIB_VERSION=1.2.7
-!ENDIF
-
-# Override to specify a particular perl executable
-!IFNDEF PERL_CMD
-PERL_CMD=perl
-!ENDIF
-
-# Where to find wget for downloading sources
-WGET=$(MSYS)\bin\wget.exe
-
-# FIXME: currently we don't respect $(FLEX) and $(BISON)
-# We assume they're in the msys directory.
-FLEX=$(MSYS)\bin\flex.exe
-TOUCH=$(MSYS)\bin\touch.exe
View
38 settings-template.mak
@@ -1,38 +0,0 @@
-# You can override any settings in settings-defaults.mak here
-
-#LIBDIR=d:\libs
-#TOOLPREFIX=d:
-
-####################################
-# Manual PostgreSQL source trees #
-####################################
-#
-# If USE_GIT is not set, PGBUILDDIR must be set to point to the path of a PostgreSQL
-# source tree - an unpacked tarball or a git working directory. You can use:
-#
-# nmake /f \path\to\pg_build_win\Makefile PGBUILDDIR=%CD%
-#
-# ... to use the current directory.
-#
-# If you want to install the resulting build, set PGINSTALLDIR to the location
-# you want to install to. If unset, the default will be to install to "binaries\"
-# under the build directory.
-#
-##############################################
-# PostgreSQL automatically managed from git #
-##############################################
-#
-#
-# If you define USE_GIT (to anything; it's not a boolean) then these build
-# scripts will perform git checkouts of the Pg source tree into a tree based
-# at PGDIR.
-#
-#USE_GIT=1
-#PGDIR=d:\postgresql
-#PG_GIT_URL=D:\postgresql-git
-#PG_BRANCH=REL9_2_STABLE
-#GIT=c:\Program Files (x86)\Git\bin\git.exe
-#
-# If you set:
-#GIT_PULL=1
-# in USE_GIT mode then the working directory will be updated before each build.
View
36 settings_template.pl
@@ -0,0 +1,36 @@
+#
+# This file configures the build. Copy it to
+# "settings.pl" and edit it to reflect your needs and
+# environment.
+#
+
+$cfg = {
+
+ 'makeargs' => {
+ 'LIBDIR' => 'c:\pg\libs',
+ 'TOOLPREFIX' => 'c:',
+
+ ####################################
+ # Manual PostgreSQL source trees #
+ ####################################
+ #
+ # If you want to install the resulting build, set PGINSTALLDIR
+ # to the location you want to install to. If unset, the default
+ # will be to install to "binaries\" under the build directory.
+ 'PGINSTALLDIR' => undef,
+
+ ##############################################
+ # PostgreSQL automatically managed from git #
+ ##############################################
+ # These settings apply only to buildgit.pl
+ 'PGDIR' => 'c:\pg\postgresql',
+ 'PG_GIT_URL' => 'c:\pg\postgresql-git',
+ 'PG_BRANCH' => 'master',
+ # The location of git will usually be autodetected, and it'll be found on
+ # the PATH if present. Set it if the scripts don't find it.
+ #'GIT' => undef
+ # if you GIT_PULL to any value in USE_GIT mode then the
+ # working directory will be updated before each build.
+ 'GIT_PULL' => 1
+ } # end of @makeargs
+};

0 comments on commit 12b852e

Please sign in to comment.