-# Set up the arguments for the main make command.
-set Makever -DSVN_REV=$(revision)
-ifneq "$(!numeric $(revision))" "yes" set Makever $(Makever) -DMODIFIED
-ifneq "$(RELEASE)" "" set Makever $(Makever) -DRELEASE=$(RELEASE)
-ifneq "$(date)" "" set Makever $(Makever) -DSNAPSHOT=$(date)
-set Makeargs VER="$(Makever)"
-ifneq "$(XFLAGS)" "" set Makeargs $(makeargs) XFLAGS="$(XFLAGS)"
-ifneq "$(MAKEARGS)" "" set Makeargs $(makeargs) $(MAKEARGS)
-
-# Set up the version string for the docs build.
-set Docmakeargs VERSION="PuTTY revision $(revision)"
-ifneq "$(RELEASE)" "" set Docmakeargs VERSION="PuTTY release $(RELEASE)"
-ifneq "$(date)" "" set Docmakeargs VERSION="PuTTY development snapshot $(date)"
-
-# Set up the version string for the Unix source archive.
-set Unxver r$(revision)
-ifneq "$(RELEASE)" "" set Unxver $(RELEASE)
-ifneq "$(date)" "" set Unxver $(date)
-
-# Set up the various version strings for the installer.
-set Iversion r$(revision)
-set Iname PuTTY revision $(revision)
-set Ivertext Revision $(revision)
-set Irev $(revision)
-set Ifilename putty-$(Iversion)-installer.exe
-ifneq "$(RELEASE)" "" set Iversion $(RELEASE)
-ifneq "$(RELEASE)" "" set Iname PuTTY version $(RELEASE)
-ifneq "$(RELEASE)" "" set Ivertext Release $(RELEASE)
-ifneq "$(RELEASE)" "" set Irev 0
+# Start by figuring out what our version information looks like.
+#
+# There are four classes of PuTTY build:
+# - a release, which just has an X.YY version number
+# - a prerelease, which has an X.YY version number, plus a date and
+# version control commit id (and is considered to be 'almost'
+# version X.YY)
+# - a development snapshot, which just has a date and commit id
+# - a custom build, which also has a date and commit id (but is
+# labelled differently, to stress that development snapshots are
+# built from the checked-in code by the automated nightly script
+# whereas custom builds are made manually, perhaps from uncommitted
+# changes, e.g. to send to a user for diagnostic or testing
+# purposes).
+#
+# The four classes of build are triggered by invoking bob with
+# different command-line variable definitions:
+#
+# - RELEASE=X.YY makes a release build
+# - PRERELEASE=X.YY makes a prerelease build (combined with the build
+# date and VCS info)
+# - setting SNAPSHOT to any non-empty string makes a development
+# snapshot
+# - setting none of these makes a custom build.
+
+# If we need a date for our build, start by computing it in the
+# various forms we need. $(Ndate) is the date in purely numeric form
+# (YYYYMMDD); $(Date) is separated as YYYY-MM-DD; $(Days) is the
+# number of days since the epoch.
+ifeq "$(RELEASE)" "" set Ndate $(!builddate)
+ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -pe 's/(....)(..)(..)/$$1-$$2-$$3/' > date
+ifneq "$(Ndate)" "" read Date date
+set Epoch 15641 # update this at every release
+ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -ne 'use Time::Local; /(....)(..)(..)/ and print timegm(0,0,0,$$3,$$2-1,$$1) / 86400 - $(Epoch)' > days
+ifneq "$(Ndate)" "" read Days days
+
+# For any non-release, we're going to need the number of the prior
+# release, for putting in various places so as to get monotonic
+# comparisons with the surrounding actual releases.
+ifeq "$(RELEASE)" "" read Lastver putty/LATEST.VER
+
+# Set up the textual version strings for the docs build and installer.
+# We have one of these including the word 'PuTTY', and one without,
+# which are inconveniently capitalised differently.
+ifneq "$(RELEASE)" "" set Puttytextver PuTTY release $(RELEASE)
+ifneq "$(RELEASE)" "" set Textver Release $(RELEASE)
+ifneq "$(PRERELEASE)" "" set Puttytextver PuTTY pre-release $(PRERELEASE):$(Date).$(vcsid)
+ifneq "$(PRERELEASE)" "" set Textver Pre-release $(PRERELEASE):$(Date).$(vcsid)
+ifneq "$(SNAPSHOT)" "" set Puttytextver PuTTY development snapshot $(Date).$(vcsid)
+ifneq "$(SNAPSHOT)" "" set Textver Development snapshot $(Date).$(vcsid)
+ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Puttytextver PuTTY custom build $(Date).$(vcsid)
+ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Textver Custom build $(Date).$(vcsid)
+set Docmakever VERSION="$(Puttytextver)"
+
+# Set up the version string for use in the SSH connection greeting.
+#
+# We use $(Ndate) rather than $(Date) in the pre-release string to
+# make sure it's under 40 characters, which is a hard limit in the SSH
+# protocol spec (and enforced by a compile-time assertion in
+# version.c).
+ifneq "$(RELEASE)" "" set Sshver PuTTY-Release-$(RELEASE)
+ifneq "$(PRERELEASE)" "" set Sshver PuTTY-Prerelease-$(PRERELEASE):$(Ndate).$(vcsid)
+ifneq "$(SNAPSHOT)" "" set Sshver PuTTY-Snapshot-$(Date).$(vcsid)
+ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Sshver PuTTY-Custom-$(Date).$(vcsid)
+
+# Set up the filename suffix for the Unix source archive.
+ifneq "$(RELEASE)" "" set Uxarcsuffix -$(RELEASE)
+ifneq "$(PRERELEASE)" "" set Uxarcsuffix -$(PRERELEASE)~pre$(Ndate).$(vcsid)
+ifneq "$(SNAPSHOT)" "" set Uxarcsuffix -$(Lastver)-$(Date).$(vcsid)
+ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Uxarcsuffix -custom-$(Date).$(vcsid)
+
+# Set up the version number for the autoconf system.
+ifneq "$(RELEASE)" "" set Autoconfver $(RELEASE)
+ifneq "$(PRERELEASE)" "" set Autoconfver $(PRERELEASE)~pre$(Ndate).$(vcsid)
+ifneq "$(SNAPSHOT)" "" set Autoconfver $(Lastver)-$(Date).$(vcsid)
+ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Autoconfver Custom.$(Date).$(vcsid)
+
+# Set up the filename for the Windows installer.