]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - Buildscr
first pass
[PuTTY.git] / Buildscr
1 # -*- sh -*-
2 # Build script to construct a full distribution directory of PuTTY.
3
4 module putty
5
6 # Start by figuring out what our version information looks like.
7 #
8 # There are four classes of PuTTY build:
9 #  - a release, which just has an X.YY version number
10 #  - a prerelease, which has an X.YY version number, plus a date and
11 #    version control commit id (and is considered to be 'almost'
12 #    version X.YY)
13 #  - a development snapshot, which just has a date and commit id
14 #  - a custom build, which also has a date and commit id (but is
15 #    labelled differently, to stress that development snapshots are
16 #    built from the checked-in code by the automated nightly script
17 #    whereas custom builds are made manually, perhaps from uncommitted
18 #    changes, e.g. to send to a user for diagnostic or testing
19 #    purposes).
20 #
21 # The four classes of build are triggered by invoking bob with
22 # different command-line variable definitions:
23 #
24 #  - RELEASE=X.YY makes a release build
25 #  - PRERELEASE=X.YY makes a prerelease build (combined with the build
26 #    date and VCS info)
27 #  - setting SNAPSHOT to any non-empty string makes a development
28 #    snapshot
29 #  - setting none of these makes a custom build.
30
31 # If we need a date for our build, start by computing it in the
32 # various forms we need. $(Ndate) is the date in purely numeric form
33 # (YYYYMMDD); $(Date) is separated as YYYY-MM-DD; $(Days) is the
34 # number of days since the epoch.
35 ifeq "$(RELEASE)" "" set Ndate $(!builddate)
36 ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -pe 's/(....)(..)(..)/$$1-$$2-$$3/' > date
37 ifneq "$(Ndate)" "" read Date date
38 set Epoch 16214 # update this at every release
39 ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -ne 'use Time::Local; /(....)(..)(..)/ and print timegm(0,0,0,$$3,$$2-1,$$1) / 86400 - $(Epoch)' > days
40 ifneq "$(Ndate)" "" read Days days
41
42 # For any non-release, we're going to need the number of the prior
43 # release, for putting in various places so as to get monotonic
44 # comparisons with the surrounding actual releases.
45 ifeq "$(RELEASE)" "" read Lastver putty/LATEST.VER
46
47 # Set up the textual version strings for the docs build and installer.
48 # We have one of these including the word 'PuTTY', and one without,
49 # which are inconveniently capitalised differently.
50 ifneq "$(RELEASE)" "" set Puttytextver PuTTY release $(RELEASE)
51 ifneq "$(RELEASE)" "" set Textver Release $(RELEASE)
52 ifneq "$(PRERELEASE)" "" set Puttytextver PuTTY pre-release $(PRERELEASE):$(Date).$(vcsid)
53 ifneq "$(PRERELEASE)" "" set Textver Pre-release $(PRERELEASE):$(Date).$(vcsid)
54 ifneq "$(SNAPSHOT)" "" set Puttytextver PuTTY development snapshot $(Date).$(vcsid)
55 ifneq "$(SNAPSHOT)" "" set Textver Development snapshot $(Date).$(vcsid)
56 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Puttytextver PuTTY custom build $(Date).$(vcsid)
57 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Textver Custom build $(Date).$(vcsid)
58 set Docmakever VERSION="$(Puttytextver)"
59
60 # Set up the version string for use in the SSH connection greeting.
61 #
62 # We use $(Ndate) rather than $(Date) in the pre-release string to
63 # make sure it's under 40 characters, which is a hard limit in the SSH
64 # protocol spec (and enforced by a compile-time assertion in
65 # version.c).
66 ifneq "$(RELEASE)" "" set Sshver PuTTY-Release-$(RELEASE)
67 ifneq "$(PRERELEASE)" "" set Sshver PuTTY-Prerelease-$(PRERELEASE):$(Ndate).$(vcsid)
68 ifneq "$(SNAPSHOT)" "" set Sshver PuTTY-Snapshot-$(Date).$(vcsid)
69 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Sshver PuTTY-Custom-$(Date).$(vcsid)
70
71 # Set up the filename suffix for the Unix source archive.
72 ifneq "$(RELEASE)" "" set Uxarcsuffix -$(RELEASE)
73 ifneq "$(PRERELEASE)" "" set Uxarcsuffix -$(PRERELEASE)~pre$(Ndate).$(vcsid)
74 ifneq "$(SNAPSHOT)" "" set Uxarcsuffix -$(Lastver)-$(Date).$(vcsid)
75 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Uxarcsuffix -custom-$(Date).$(vcsid)
76
77 # Set up the version number for the autoconf system.
78 ifneq "$(RELEASE)" "" set Autoconfver $(RELEASE)
79 ifneq "$(PRERELEASE)" "" set Autoconfver $(PRERELEASE)~pre$(Ndate).$(vcsid)
80 ifneq "$(SNAPSHOT)" "" set Autoconfver $(Lastver)-$(Date).$(vcsid)
81 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Autoconfver Custom.$(Date).$(vcsid)
82
83 # Set up the filenames for the Windows installer (minus extension,
84 # which goes on later).
85 ifneq "$(RELEASE)" "" set Isuffix $(RELEASE)-installer
86 ifneq "$(PRERELEASE)" "" set Isuffix $(PRERELEASE)-pre$(Ndate)-installer
87 ifneq "$(SNAPSHOT)" "" set Isuffix $(Date)-installer
88 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Isuffix custom-$(Date)-installer
89 set Ifilename32 putty-$(Isuffix)
90 set Ifilename64 putty-64bit-$(Isuffix)
91
92 # Set up the version string for the Windows installer.
93 ifneq "$(RELEASE)" "" set Iversion $(RELEASE)
94 ifneq "$(PRERELEASE)" "" set Iversion $(PRERELEASE)-pre$(Ndate).$(vcsid)
95 ifneq "$(SNAPSHOT)" "" set Iversion $(Date).$(vcsid)
96 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Iversion Custom-$(Date).$(vcsid)
97
98 # Set up the Windows version resource info, for both the installer and
99 # the individual programs. This must be a sequence of four 16-bit
100 # integers compared lexicographically, and we define it as follows:
101 #
102 #   For release X.YY:                             X.YY.0.0
103 #   For a prerelease before the X.YY release:     (X.YY-1).(DDDDD + 0x8000).0
104 #   For a devel snapshot after the X.YY release:  X.YY.DDDDD.0
105 #   For a custom build:                           X.YY.DDDDD.1
106 #
107 # where DDDDD is a representation of the build date, in the form of a
108 # number of days since an epoch date. The epoch is reset at every
109 # release (which, with 15 bits, gives us a comfortable 80-odd years
110 # before it becomes vital to make another release to reset the count
111 # :-).
112
113 ifneq "$(RELEASE)" "" in . do echo $(RELEASE).0.0 > winver
114 ifneq "$(PRERELEASE)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], 0x8000+$$ARGV[1]' $(Lastver) $(Days) > winver
115 ifneq "$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
116 ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.1", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
117 in . do perl -pe 'y!.!,!' winver > winvercommas
118 read Winver winver
119 read Winvercommas winvercommas
120
121 # Write out a version.h that contains the real version number.
122 in putty do echo '/* Generated by automated build script */' > version.h
123 ifneq "$(RELEASE)" "" in putty do echo '$#define RELEASE $(RELEASE)' >> version.h
124 ifneq "$(PRERELEASE)" "" in putty do echo '$#define PRERELEASE $(PRERELEASE)' >> version.h
125 ifneq "$(SNAPSHOT)" "" in putty do echo '$#define SNAPSHOT' >> version.h
126 in putty do echo '$#define TEXTVER "$(Textver)"' >> version.h
127 in putty do echo '$#define SSHVER "$(Sshver)"' >> version.h
128 in putty do echo '$#define BINARY_VERSION $(Winvercommas)' >> version.h
129 in putty do echo '$#define SOURCE_COMMIT "$(vcsfullid)"' >> version.h
130
131 # Set up the extra arguments for the main Windows nmake command. The
132 # user can define XFLAGS and MAKEARGS on the bob command line, to pass
133 # in extra compile and make options respectively (e.g. to do a
134 # debugging or Minefield build).
135 set Makeargs
136 ifneq "$(XFLAGS)" "" set Makeargs $(Makeargs) XFLAGS="$(XFLAGS)"
137 ifneq "$(MAKEARGS)" "" set Makeargs $(Makeargs) $(MAKEARGS)
138
139 in putty do ./mksrcarc.sh
140 in putty do ./mkunxarc.sh '$(Autoconfver)' '$(Uxarcsuffix)' $(Docmakever)
141 in putty do perl mkfiles.pl
142 in putty/doc do make $(Docmakever) putty.hlp
143 in putty/doc do make $(Docmakever) chm
144
145 # Munge the installer script locally so that it reports the version
146 # we're really building.
147 in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(AppVerName=).*$$/$$1$$a/' '$(Puttytextver)' putty.iss
148 in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(VersionInfoTextVersion=).*$$/$$1$$a/' '$(Textver)' putty.iss
149 in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(AppVersion=).*$$/$$1$$a/' '$(Iversion)' putty.iss
150 in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(VersionInfoVersion=)\d+\.\d+\.\d+\.\d+\r?$$/$$1$$a/' '$(Winver)' putty.iss
151
152 # Windowsify LICENCE, since it's going in the Windows installer.
153 in putty do perl -i~ -pe 'y/\015//d;s/$$/\015/' LICENCE
154
155 # Some gratuitous theming for the MSI installer UI.
156 in putty/icons do make
157 in putty do convert -size 164x312 'gradient:blue-white' -distort SRT -90 -swirl 180 \( -size 329x312 canvas:white \) +append \( icons/putty-48.png -geometry +28+24 \) -composite \( icons/pscp-48.png -geometry +88+96 \) -composite \( icons/puttygen-48.png -geometry +28+168 \) -composite \( icons/pageant-48.png -geometry +88+240 \) -composite windows/msidialog.bmp
158 in putty do convert -size 493x58 canvas:white \( icons/putty-48.png -geometry +440+5 \) -composite windows/msibanner.bmp
159
160 delegate windows
161   # Build the original binaries.
162   in putty/windows with visualstudio do/win mkdir buildold && nmake -f Makefile.vc BUILDDIR=buildold\ $(Makeargs) all cleantestprogs
163
164   # Build the VS2015 binaries. For the 32-bit ones, we set a subsystem
165   # version of 5.01, which allows the resulting files to still run on
166   # Windows XP.
167   in putty/windows with visualstudio2015_32bit do/win mkdir build32 && nmake -f Makefile.vc BUILDDIR=build32\ SUBSYSVER=,5.01 $(Makeargs) all cleantestprogs
168   in putty/windows with visualstudio2015_64bit do/win mkdir build64 && nmake -f Makefile.vc BUILDDIR=build64\ $(Makeargs) all cleantestprogs
169
170   # Code-sign the binaries, if the local bob config provides a script
171   # to do so. We assume here that the script accepts an -i option to
172   # provide a 'more info' URL, and an optional -n option to provide a
173   # program name, and that it can take multiple .exe filename
174   # arguments and sign them all in place.
175   ifneq "$(winsigncode)" "" in putty/windows do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/putty/ build*/*.exe
176
177   # Ignore exit code from hhc, in favour of seeing whether the .chm
178   # file was created. (Yuck; but hhc appears to return non-zero
179   # exit codes on whim.)
180   in putty/doc with htmlhelp do/win hhc putty.hhp & type putty.chm >nul
181
182   # Build a WiX MSI installer, for each of build32 and build64.
183   in putty/windows with wix do/win candle -arch x86 -dWin64=no -dBuilddir=build32\ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installer32.msi
184   in putty/windows with wix do/win candle -arch x64 -dWin64=yes -dBuilddir=build64\ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installer64.msi
185
186   # Build the old Inno Setup installer, for 32-bit only.
187   in putty/windows with innosetup do/win iscc putty.iss
188
189   # Sign the installers.
190   ifneq "$(winsigncode)" "" in putty/windows do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/putty/ -n "PuTTY Installer" installer32.msi installer64.msi Output/installer.exe
191
192   # Finished Windows builds.
193   return putty/windows/buildold/*.exe
194   return putty/windows/buildold/*.map
195   return putty/windows/build32/*.exe
196   return putty/windows/build32/*.map
197   return putty/windows/build64/*.exe
198   return putty/windows/build64/*.map
199   return putty/doc/putty.chm
200   return putty/windows/installer32.msi
201   return putty/windows/installer64.msi
202   return putty/windows/Output/installer.exe
203 enddelegate
204 in putty/doc do make mostlyclean
205 in putty/doc do make $(Docmakever)
206 in putty/windows/buildold do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm ../../doc/putty.hlp ../../doc/putty.cnt
207 in putty/windows/build32 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm ../../doc/putty.hlp ../../doc/putty.cnt
208 in putty/windows/build64 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm ../../doc/putty.hlp ../../doc/putty.cnt
209 in putty/doc do zip puttydoc.zip *.html
210
211 # Deliver the actual PuTTY release directory into a subdir `putty'.
212 deliver putty/windows/buildold/*.exe putty/w32old/$@
213 deliver putty/windows/buildold/putty.zip putty/w32old/$@
214 deliver putty/windows/build32/*.exe putty/w32/$@
215 deliver putty/windows/build32/putty.zip putty/w32/$@
216 deliver putty/windows/build64/*.exe putty/w64/$@
217 deliver putty/windows/build64/putty.zip putty/w64/$@
218 deliver putty/windows/installer32.msi putty/w32/$(Ifilename32).msi
219 deliver putty/windows/installer64.msi putty/w64/$(Ifilename64).msi
220 deliver putty/windows/Output/installer.exe putty/w32/$(Ifilename32).exe
221 deliver putty/doc/puttydoc.zip putty/$@
222 deliver putty/doc/putty.chm putty/$@
223 deliver putty/doc/putty.hlp putty/$@
224 deliver putty/doc/putty.cnt putty/$@
225 deliver putty/doc/puttydoc.txt putty/$@
226 deliver putty/doc/*.html putty/htmldoc/$@
227 deliver putty/putty-src.zip putty/$@
228 deliver putty/*.tar.gz putty/$@
229
230 # Deliver the map files alongside the `proper' release deliverables.
231 deliver putty/windows/buildold/*.map maps/w32old/$@
232 deliver putty/windows/build32/*.map maps/w32/$@
233 deliver putty/windows/build64/*.map maps/w64/$@
234
235 # Deliver sign.sh, so that whoever has just built PuTTY (the
236 # snapshot scripts or me, depending) can conveniently sign it with
237 # whatever key they want.
238 deliver putty/sign.sh $@
239
240 # Create files of cryptographic checksums, which will be signed along
241 # with the files they verify. We've provided MD5 checksums for a
242 # while, but now MD5 is looking iffy, we're expanding our selection.
243 #
244 # Creating these files is most easily done in the destination
245 # directory, where all the files we're delivering are already in their
246 # final relative layout.
247 in-dest putty do a=`\find * -type f -print`; md5sum $$a > md5sums && sha1sum $$a > sha1sums && sha256sum $$a > sha256sums && sha512sum $$a > sha512sums
248
249 # And construct .htaccess files. One in the top-level directory,
250 # setting the MIME types for Windows help files and providing an
251 # appropriate link to the source archive:
252 in-dest putty do echo "AddType application/octet-stream .chm" >> .htaccess
253 in-dest putty do echo "AddType application/octet-stream .hlp" >> .htaccess
254 in-dest putty do echo "AddType application/octet-stream .cnt" >> .htaccess
255 in-dest putty do set -- putty*.tar.gz; for k in '' .gpg; do echo RedirectMatch temp '(.*/)'putty.tar.gz$$k\$$ '$$1'"$$1$$k" >> .htaccess; done
256 # And one in each binary directory, providing links for the installers.
257 in-dest putty do for params in "w32 putty-installer" "w64 putty-64bit-installer"; do (set -- $$params; subdir=$$1; installername=$$2; cd $$subdir && for ext in msi exe; do set -- putty*installer.$$ext; if test -f $$1; then for k in '' .gpg; do echo RedirectMatch temp '(.*/)'$${installername}.$$ext$$k\$$ '$$1'"$$1$$k" >> .htaccess; done; fi; done); done