--- /dev/null
+#! /usr/bin/env perl
+
+use Getopt::Long qw(:config bundling no_ignore_case);
+use POSIX;
+
+use strict;
+use warnings;
+
+my $help = 0;
+GetOptions ("h|help" => \$help);
+
+usage () if $help;
+
+die "$0: exactly one or two nonoption arguments are required\n"
+ if @ARGV != 1 && @ARGV != 2;
+
+my $buildslave = `hostname`;
+chomp $buildslave;
+
+# Select build number.
+my $buildnumber = POSIX::strftime("%Y%m%d%H%M%S", localtime);
+print "\tBUILDNUMBER=$buildnumber\n";
+
+# Create build directory.
+my $builddir = "builds/$buildnumber";
+print "Create $builddir\n";
+mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds";
+mkdir $builddir or die "$builddir: mkdir: $!\n";
+
+if (@ARGV == 2) {
+ my ($repo, $branch) = @ARGV;
+
+ # Fetch branch
+ print "Fetch $repo, branch $branch\n";
+ run ("git fetch $repo +$branch:buildtmp/$$/pspp");
+
+ # Get revision number.
+ my $revision = `git rev-parse buildtmp/$$/pspp`;
+ chomp $revision;
+ print "\tREVISION=$revision\n";
+ my $abbrev_revision = substr ($revision, 0, 6);
+
+ # Extract source.
+ print "Extract branch into $builddir/pspp$buildnumber\n";
+ run ("git archive --format=tar --prefix=pspp$buildnumber/ buildtmp/$$/pspp | (cd $builddir && tar xf -)");
+
+ # Extract version number.
+ print "Extract version number\n";
+ my $trace = `cd $builddir/pspp$buildnumber && autoconf -t AC_INIT`;
+ chomp $trace;
+ my ($file, $line, $macro, $package, $version, @rest) = split (':', $trace);
+ print "\tVERSION=$version\n";
+
+ # Append -g012345 to AC_INIT version number.
+ my $fullname = "$builddir/pspp$buildnumber/$file";
+ open (OLDFILE, '<', $fullname)
+ or die "opening $fullname failed: $!\n";
+ open (NEWFILE, '>', "$fullname.new")
+ or die "creating $fullname.new failed: $!\n";
+ while (<OLDFILE>) {
+ if ($. != $line) {
+ print NEWFILE $_;
+ } else {
+ print NEWFILE "AC_INIT([[$package]]";
+ print NEWFILE ", [[$version-g$abbrev_revision]]";
+ print NEWFILE ", [[$_]]" foreach @rest;
+ print NEWFILE ")\n";
+ }
+ }
+ close (NEWFILE);
+ close (OLDFILE);
+ rename ("$fullname.new", $fullname)
+ or die "rename $fullname.new to $fullname failed: $!\n";
+
+ # Add note to beginning of NEWS (otherwise "make dist" fails).
+ $fullname = "$builddir/pspp$buildnumber/NEWS";
+ open (OLDFILE, '<', $fullname)
+ or die "opening $fullname failed: $!\n";
+ open (NEWFILE, '>', "$fullname.new")
+ or die "creating $fullname.new failed: $!\n";
+ my $found_changes = 0;
+ while (<OLDFILE>) {
+ if (!$found_changes && /^Changes/) {
+ $found_changes = 1;
+ print NEWFILE <<EOF;
+Changes from $version to $version-g$abbrev_revision:
+
+ * Built automatically from commit $revision
+ in branch $branch on build slave $buildslave
+
+EOF
+ }
+ print NEWFILE $_;
+ }
+ close (NEWFILE);
+ close (OLDFILE);
+ rename ("$fullname.new", $fullname)
+ or die "rename $fullname.new to $fullname failed: $!\n";
+
+
+}
+
+sub usage {
+ print <<EOF;
+$0, for building and testing PSPP
+usage: $0 [OPTIONS] [TARBALL | REPO REFSPEC]
+where TARBALL is the name of a tarball produced by "make dist"
+ or REPO and REFSPEC are a Git repo and refspec (e.g. branch) to clone.
+
+Options:
+ --help Print this usage message and exit
+EOF
+ exit(0);
+}
+
+sub run {
+ my ($command) = @_;
+ return if system ($command) == 0;
+ if ($? == -1) {
+ print "$command: failed to execute: $!\n";
+ } elsif ($? & 127) {
+ printf "%s: child died with signal %d, %s coredump\n",
+ $command, ($? & 127), ($? & 128) ? 'with' : 'without';
+ } else {
+ printf "%s: child exited with value %d\n", $command, $? >> 8;
+ }
+ exit 1;
+}
+
+# Clone source
+# Add build number
+# Tag build
+# Clone gnulib at correct commit number
+# Run gnulib-tool.
+# Run configure
+# Make dist
+
+# Unpack dist
+# Run configure
+# Check
+# Install
+# Make binary dist
+# Build mingw32 installer
+# Other distcheck stuff?