Buildscr 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. # -*- sh -*-
  2. # Build script to construct a full distribution directory of PuTTY.
  3. module putty
  4. # Start by figuring out what our version information looks like.
  5. #
  6. # There are four classes of PuTTY build:
  7. # - a release, which just has an X.YY version number
  8. # - a prerelease, which has an X.YY version number, plus a date and
  9. # version control commit id (and is considered to be 'almost'
  10. # version X.YY)
  11. # - a development snapshot, which just has a date and commit id
  12. # - a custom build, which also has a date and commit id (but is
  13. # labelled differently, to stress that development snapshots are
  14. # built from the checked-in code by the automated nightly script
  15. # whereas custom builds are made manually, perhaps from uncommitted
  16. # changes, e.g. to send to a user for diagnostic or testing
  17. # purposes).
  18. #
  19. # The four classes of build are triggered by invoking bob with
  20. # different command-line variable definitions:
  21. #
  22. # - RELEASE=X.YY makes a release build
  23. # - PRERELEASE=X.YY makes a prerelease build (combined with the build
  24. # date and VCS info)
  25. # - setting SNAPSHOT to any non-empty string makes a development
  26. # snapshot
  27. # - setting none of these makes a custom build.
  28. # If we need a date for our build, start by computing it in the
  29. # various forms we need. $(Ndate) is the date in purely numeric form
  30. # (YYYYMMDD); $(Date) is separated as YYYY-MM-DD; $(Days) is the
  31. # number of days since the epoch.
  32. ifeq "$(RELEASE)" "" set Ndate $(!builddate)
  33. ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -pe 's/(....)(..)(..)/$$1-$$2-$$3/' > date
  34. ifneq "$(Ndate)" "" read Date date
  35. set Epoch 17818 # update this at every release
  36. ifneq "$(Ndate)" "" in . do echo $(Ndate) | perl -ne 'use Time::Local; /(....)(..)(..)/ and print timegm(0,0,0,$$3,$$2-1,$$1) / 86400 - $(Epoch)' > days
  37. ifneq "$(Ndate)" "" read Days days
  38. # For any non-release, we're going to need the number of the prior
  39. # release, for putting in various places so as to get monotonic
  40. # comparisons with the surrounding actual releases.
  41. ifeq "$(RELEASE)" "" read Lastver putty/LATEST.VER
  42. # Set up the textual version strings for the docs build and installers.
  43. # We have one of these including the word 'PuTTY', and one without,
  44. # which are inconveniently capitalised differently.
  45. ifneq "$(RELEASE)" "" set Puttytextver PuTTY release $(RELEASE)
  46. ifneq "$(RELEASE)" "" set Textver Release $(RELEASE)
  47. ifneq "$(PRERELEASE)" "" set Puttytextver PuTTY pre-release $(PRERELEASE):$(Date).$(vcsid)
  48. ifneq "$(PRERELEASE)" "" set Textver Pre-release $(PRERELEASE):$(Date).$(vcsid)
  49. ifneq "$(SNAPSHOT)" "" set Puttytextver PuTTY development snapshot $(Date).$(vcsid)
  50. ifneq "$(SNAPSHOT)" "" set Textver Development snapshot $(Date).$(vcsid)
  51. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Puttytextver PuTTY custom build $(Date).$(vcsid)
  52. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Textver Custom build $(Date).$(vcsid)
  53. set Docmakever VERSION="$(Puttytextver)"
  54. # Set up the version string for use in the SSH connection greeting.
  55. #
  56. # We use $(Ndate) rather than $(Date) in the pre-release string to
  57. # make sure it's under 40 characters, which is a hard limit in the SSH
  58. # protocol spec (and enforced by a compile-time assertion in
  59. # version.c).
  60. ifneq "$(RELEASE)" "" set Sshver -Release-$(RELEASE)
  61. ifneq "$(PRERELEASE)" "" set Sshver -Prerelease-$(PRERELEASE):$(Ndate).$(vcsid)
  62. ifneq "$(SNAPSHOT)" "" set Sshver -Snapshot-$(Date).$(vcsid)
  63. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Sshver -Custom-$(Date).$(vcsid)
  64. # Set up the filename suffix for the Unix source archive.
  65. ifneq "$(RELEASE)" "" set Uxarcsuffix -$(RELEASE)
  66. ifneq "$(PRERELEASE)" "" set Uxarcsuffix -$(PRERELEASE)~pre$(Ndate).$(vcsid)
  67. ifneq "$(SNAPSHOT)" "" set Uxarcsuffix -$(Lastver)-$(Date).$(vcsid)
  68. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Uxarcsuffix -custom-$(Date).$(vcsid)
  69. # Set up the version number for the autoconf system.
  70. ifneq "$(RELEASE)" "" set Autoconfver $(RELEASE)
  71. ifneq "$(PRERELEASE)" "" set Autoconfver $(PRERELEASE)~pre$(Ndate).$(vcsid)
  72. ifneq "$(SNAPSHOT)" "" set Autoconfver $(Lastver)-$(Date).$(vcsid)
  73. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Autoconfver Custom.$(Date).$(vcsid)
  74. # Set up the filenames for the Windows installers (minus extension,
  75. # which goes on later).
  76. ifneq "$(RELEASE)" "" set Isuffix $(RELEASE)-installer
  77. ifneq "$(PRERELEASE)" "" set Isuffix $(PRERELEASE)-pre$(Ndate)-installer
  78. ifneq "$(SNAPSHOT)" "" set Isuffix $(Date)-installer
  79. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Isuffix custom-$(Date)-installer
  80. set Ifilename32 putty-$(Isuffix)
  81. set Ifilename64 putty-64bit-$(Isuffix)
  82. set Ifilenamea32 putty-arm32-$(Isuffix)
  83. set Ifilenamea64 putty-arm64-$(Isuffix)
  84. # Set up the Windows version resource info, for both the installers and
  85. # the individual programs. This must be a sequence of four 16-bit
  86. # integers compared lexicographically, and we define it as follows:
  87. #
  88. # For release X.YY: X.YY.0.0
  89. # For a prerelease before the X.YY release: (X.YY-1).(DDDDD + 0x8000).0
  90. # For a devel snapshot after the X.YY release: X.YY.DDDDD.0
  91. # For a custom build: X.YY.DDDDD.1
  92. #
  93. # where DDDDD is a representation of the build date, in the form of a
  94. # number of days since an epoch date. The epoch is reset at every
  95. # release (which, with 15 bits, gives us a comfortable 80-odd years
  96. # before it becomes vital to make another release to reset the count
  97. # :-).
  98. ifneq "$(RELEASE)" "" in . do echo $(RELEASE).0.0 > winver
  99. ifneq "$(PRERELEASE)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], 0x8000+$$ARGV[1]' $(Lastver) $(Days) > winver
  100. ifneq "$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
  101. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.1", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
  102. in . do perl -pe 'y!.!,!' winver > winvercommas
  103. read Winver winver
  104. read Winvercommas winvercommas
  105. # Write out a version.h that contains the real version number.
  106. in putty do echo '/* Generated by automated build script */' > version.h
  107. ifneq "$(RELEASE)" "" in putty do echo '$#define RELEASE $(RELEASE)' >> version.h
  108. ifneq "$(PRERELEASE)" "" in putty do echo '$#define PRERELEASE $(PRERELEASE)' >> version.h
  109. ifneq "$(SNAPSHOT)" "" in putty do echo '$#define SNAPSHOT' >> version.h
  110. in putty do echo '$#define TEXTVER "$(Textver)"' >> version.h
  111. in putty do echo '$#define SSHVER "$(Sshver)"' >> version.h
  112. in putty do echo '$#define BINARY_VERSION $(Winvercommas)' >> version.h
  113. in putty do echo '$#define SOURCE_COMMIT "$(vcsfullid)"' >> version.h
  114. # Set up the extra arguments for the main Windows nmake command. The
  115. # user can define XFLAGS and MAKEARGS on the bob command line, to pass
  116. # in extra compile and make options respectively (e.g. to do a
  117. # debugging or Minefield build).
  118. set Makeargs
  119. ifneq "$(XFLAGS)" "" set Makeargs $(Makeargs) XFLAGS="$(XFLAGS)"
  120. ifneq "$(MAKEARGS)" "" set Makeargs $(Makeargs) $(MAKEARGS)
  121. in putty do ./mksrcarc.sh
  122. in putty do ./mkunxarc.sh '$(Autoconfver)' '$(Uxarcsuffix)' $(Docmakever)
  123. in putty do perl mkfiles.pl
  124. in putty/doc do make $(Docmakever) putty.chm -j$(nproc)
  125. delegate -
  126. # Run the test suite, under self-delegation so that we don't leave any
  127. # cruft lying around. This involves doing a build of the Unix tools
  128. # (which is a useful double-check anyway to pick up any build failures)
  129. in putty do ./mkauto.sh
  130. in putty do ./configure CC=clang CFLAGS="-fsanitize=address -fsanitize=leak"
  131. in putty do make -j$(nproc)
  132. in putty do python3 test/cryptsuite.py
  133. enddelegate
  134. # Windowsify LICENCE, since it's going in the Windows installers.
  135. in putty do perl -i~ -pe 'y/\015//d;s/$$/\015/' LICENCE
  136. # Some gratuitous theming for the MSI installer UI.
  137. in putty/icons do make -j$(nproc)
  138. in putty do ./windows/make_install_images.sh
  139. mkdir putty/windows/build32
  140. mkdir putty/windows/build64
  141. mkdir putty/windows/buildold
  142. mkdir putty/windows/abuild32
  143. mkdir putty/windows/abuild64
  144. # Build the binaries to go in the installers, in both 32- and 64-bit
  145. # flavours.
  146. #
  147. # For the 32-bit ones, we set a subsystem version of 5.01, which
  148. # allows the resulting files to still run on Windows XP.
  149. in putty/windows with clangcl32 do Platform=x86 make -f Makefile.clangcl BUILDDIR=build32/ SUBSYSVER=,5.01 $(Makeargs) all -j$(nproc)
  150. in putty/windows with clangcl64 do Platform=x64 make -f Makefile.clangcl BUILDDIR=build64/ $(Makeargs) all -j$(nproc)
  151. # Build experimental Arm Windows binaries.
  152. in putty/windows with clangcl_a32 do Platform=arm make -f Makefile.clangcl BUILDDIR=abuild32/ SUBSYSVER=,5.01 $(Makeargs) all -j$(nproc)
  153. in putty/windows with clangcl_a64 do Platform=arm64 make -f Makefile.clangcl BUILDDIR=abuild64/ $(Makeargs) all -j$(nproc)
  154. # Remove Windows binaries for the test programs we don't want to ship,
  155. # like testcrypt.exe. (But we still _built_ them, to ensure the build
  156. # worked.)
  157. in putty/windows do make -f Makefile.clangcl BUILDDIR=build32/ cleantestprogs
  158. in putty/windows do make -f Makefile.clangcl BUILDDIR=build64/ cleantestprogs
  159. in putty/windows do make -f Makefile.clangcl BUILDDIR=abuild32/ cleantestprogs
  160. in putty/windows do make -f Makefile.clangcl BUILDDIR=abuild64/ cleantestprogs
  161. # Code-sign the Windows binaries, if the local bob config provides a
  162. # script to do so in a cross-compiling way. We assume here that the
  163. # script accepts an -i option to provide a 'more info' URL, an
  164. # optional -n option to provide a program name, and an -N option to
  165. # take the program name from an .exe's version resource, and that it
  166. # can accept multiple .exe or .msi filename arguments and sign them
  167. # all in place.
  168. ifneq "$(cross_winsigncode)" "" in putty/windows do $(cross_winsigncode) -N -i https://www.chiark.greenend.org.uk/~sgtatham/putty/ build*/*.exe abuild*/*.exe
  169. # Make a preliminary set of cryptographic checksums giving the hashes
  170. # of these versions of the binaries. We'll make the rest below.
  171. in putty do for hash in md5 sha1 sha256 sha512; do for dir_plat in "build32 w32" "build64 w64" "abuild32 wa32" "abuild64 wa64"; do set -- $$dir_plat; (cd windows/$$1 && $${hash}sum *.exe | sed 's!\( \+\)!\1'$$2'/!;s!$$! (installer version)!') >> $${hash}sums.installer; done; done
  172. # Build a WiX MSI installer, for each build flavour.
  173. in putty/windows with wixonlinux do candle -arch x86 -dRealPlatform=x86 -dDllOk=yes -dBuilddir=build32/ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installer32.msi -spdb
  174. in putty/windows with wixonlinux do candle -arch x64 -dRealPlatform=x64 -dDllOk=yes -dBuilddir=build64/ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installer64.msi -spdb
  175. in putty/windows with wixonlinux do candle -arch x64 -dRealPlatform=Arm -dDllOk=no -dBuilddir=abuild32/ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installera32.msi -spdb
  176. in putty/windows with wixonlinux do candle -arch x64 -dRealPlatform=Arm64 -dDllOk=no -dBuilddir=abuild64/ -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj -o installera64.msi -spdb
  177. # Change the width field for our dialog background image so that it
  178. # doesn't stretch across the whole dialog. (WiX's default one does; we
  179. # replace it with a narrow one so that the text to the right of it
  180. # shows up on system default background colour, meaning that
  181. # high-contrast mode doesn't make the text white on white. But that
  182. # means we also have to modify the width field, and there's nothing in
  183. # WiX's source syntax to make that happen.)
  184. #
  185. # Also bodge the platform fields for the Windows on Arm installers,
  186. # since WiX 3 doesn't understand Arm platform names itself.
  187. in putty/windows do ./msifixup.py installer32.msi --dialog-bmp-width=123
  188. in putty/windows do ./msifixup.py installer64.msi --dialog-bmp-width=123
  189. in putty/windows do ./msifixup.py installera32.msi --dialog-bmp-width=123 --platform=Arm
  190. in putty/windows do ./msifixup.py installera64.msi --dialog-bmp-width=123 --platform=Arm64
  191. # Sign the Windows installers.
  192. ifneq "$(cross_winsigncode)" "" in putty/windows do $(cross_winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/putty/ -n "PuTTY Installer" installer32.msi installer64.msi installera32.msi installera64.msi
  193. # Delete the binaries and resource files from the build directories,
  194. # so that we can rebuild them differently.
  195. in putty/windows/build32 do rm -f *.exe *.res *.rcpp
  196. in putty/windows/build64 do rm -f *.exe *.res *.rcpp
  197. in putty/windows/abuild32 do rm -f *.exe *.res *.rcpp
  198. in putty/windows/abuild64 do rm -f *.exe *.res *.rcpp
  199. # Build the standalone binaries, in both 32- and 64-bit flavours.
  200. # These differ from the previous set in that they embed the help file.
  201. in putty/windows with clangcl32 do Platform=x86 make -f Makefile.clangcl BUILDDIR=build32/ RCFL=-DEMBED_CHM SUBSYSVER=,5.01 $(Makeargs) all -j$(nproc)
  202. in putty/windows with clangcl64 do Platform=x64 make -f Makefile.clangcl BUILDDIR=build64/ RCFL=-DEMBED_CHM $(Makeargs) all -j$(nproc)
  203. in putty/windows with clangcl_a32 do Platform=arm make -f Makefile.clangcl BUILDDIR=abuild32/ RCFL=-DEMBED_CHM SUBSYSVER=,5.01 $(Makeargs) all -j$(nproc)
  204. in putty/windows with clangcl_a64 do Platform=arm64 make -f Makefile.clangcl BUILDDIR=abuild64/ RCFL=-DEMBED_CHM $(Makeargs) all -j$(nproc)
  205. # Build the 'old' binaries, which should still run on all 32-bit
  206. # versions of Windows back to Win95 (but not Win32s). These link
  207. # against Visual Studio 2003 libraries (the more modern versions
  208. # assume excessively modern Win32 API calls to be available), specify
  209. # a subsystem version of 4.0, and compile with /arch:IA32 to prevent
  210. # the use of modern CPU features like MMX which older machines also
  211. # might not have.
  212. #
  213. # There's no installer to go with these, so they must also embed the
  214. # help file.
  215. in putty/windows with clangcl32_2003 do Platform=x86 make -f Makefile.clangcl BUILDDIR=buildold/ RCFL=-DEMBED_CHM $(Makeargs) CCTARGET=i386-pc-windows-msvc13.0.0 SUBSYSVER=,4.0 EXTRA_windows=wincrt0.obj EXTRA_console=crt0.obj EXTRA_libs=libcpmt.lib XFLAGS="/arch:IA32 -Wno-pragma-pack" all -j$(nproc)
  216. # Remove test programs again.
  217. in putty/windows do make -f Makefile.clangcl BUILDDIR=build32/ cleantestprogs
  218. in putty/windows do make -f Makefile.clangcl BUILDDIR=build64/ cleantestprogs
  219. in putty/windows do make -f Makefile.clangcl BUILDDIR=abuild32/ cleantestprogs
  220. in putty/windows do make -f Makefile.clangcl BUILDDIR=abuild64/ cleantestprogs
  221. in putty/windows do make -f Makefile.clangcl BUILDDIR=buildold/ cleantestprogs
  222. # Code-sign the standalone versions of the binaries.
  223. ifneq "$(cross_winsigncode)" "" in putty/windows do $(cross_winsigncode) -N -i https://www.chiark.greenend.org.uk/~sgtatham/putty/ build*/*.exe abuild*/*.exe
  224. in putty/doc do make mostlyclean
  225. in putty/doc do make $(Docmakever) -j$(nproc)
  226. in putty/windows/buildold do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm
  227. in putty/windows/build32 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm
  228. in putty/windows/build64 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm
  229. in putty/windows/abuild32 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm
  230. in putty/windows/abuild64 do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../../doc/putty.chm
  231. in putty/doc do zip puttydoc.zip *.html
  232. # Deliver the actual PuTTY release directory into a subdir `putty'.
  233. deliver putty/windows/buildold/*.exe putty/w32old/$@
  234. deliver putty/windows/buildold/putty.zip putty/w32old/$@
  235. deliver putty/windows/build32/*.exe putty/w32/$@
  236. deliver putty/windows/build32/putty.zip putty/w32/$@
  237. deliver putty/windows/build64/*.exe putty/w64/$@
  238. deliver putty/windows/build64/putty.zip putty/w64/$@
  239. deliver putty/windows/installer32.msi putty/w32/$(Ifilename32).msi
  240. deliver putty/windows/installer64.msi putty/w64/$(Ifilename64).msi
  241. deliver putty/windows/installera32.msi putty/wa32/$(Ifilenamea32).msi
  242. deliver putty/windows/installera64.msi putty/wa64/$(Ifilenamea64).msi
  243. deliver putty/windows/abuild32/*.exe putty/wa32/$@
  244. deliver putty/windows/abuild32/putty.zip putty/wa32/$@
  245. deliver putty/windows/abuild64/*.exe putty/wa64/$@
  246. deliver putty/windows/abuild64/putty.zip putty/wa64/$@
  247. deliver putty/doc/puttydoc.zip putty/$@
  248. deliver putty/doc/putty.chm putty/$@
  249. deliver putty/doc/puttydoc.txt putty/$@
  250. deliver putty/doc/*.html putty/htmldoc/$@
  251. deliver putty/putty-src.zip putty/$@
  252. deliver putty/*.tar.gz putty/$@
  253. # Deliver the map files alongside the `proper' release deliverables.
  254. deliver putty/windows/buildold/*.map maps/w32old/$@
  255. deliver putty/windows/build32/*.map maps/w32/$@
  256. deliver putty/windows/build64/*.map maps/w64/$@
  257. deliver putty/windows/abuild32/*.map maps/wa32/$@
  258. deliver putty/windows/abuild64/*.map maps/wa64/$@
  259. # Deliver sign.sh, so that whoever has just built PuTTY (the
  260. # snapshot scripts or me, depending) can conveniently sign it with
  261. # whatever key they want.
  262. deliver putty/sign.sh $@
  263. # Create files of cryptographic checksums, which will be signed along
  264. # with the files they verify. We've provided MD5 checksums for a
  265. # while, but now MD5 is looking iffy, we're expanding our selection.
  266. #
  267. # Creating these files is most easily done in the destination
  268. # directory, where all the files we're delivering are already in their
  269. # final relative layout.
  270. in . do pwd > builddir
  271. read Builddir builddir
  272. in-dest putty do a=`\find * -type f -print`; for hash in md5 sha1 sha256 sha512; do ($${hash}sum $$a; echo; cat $(Builddir)/putty/$${hash}sums.installer) > $${hash}sums; done
  273. # And construct .htaccess files. One in the top-level directory,
  274. # setting the MIME types for Windows help files and providing an
  275. # appropriate link to the source archive:
  276. in-dest putty do echo "AddType application/octet-stream .chm" >> .htaccess
  277. 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
  278. # And one in each binary directory, providing links for the installers.
  279. in-dest putty do for params in "w32 putty-installer" "w64 putty-64bit-installer" "wa32 putty-arm32-installer" "wa64 putty-arm64-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