Buildscr 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 15860 # 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 installer.
  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 PuTTY-Release-$(RELEASE)
  61. ifneq "$(PRERELEASE)" "" set Sshver PuTTY-Prerelease-$(PRERELEASE):$(Ndate).$(vcsid)
  62. ifneq "$(SNAPSHOT)" "" set Sshver PuTTY-Snapshot-$(Date).$(vcsid)
  63. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Sshver PuTTY-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 filename for the Windows installer (minus extension,
  75. # which goes on later).
  76. ifneq "$(RELEASE)" "" set Ifilename putty-$(RELEASE)-installer
  77. ifneq "$(PRERELEASE)" "" set Ifilename putty-$(PRERELEASE)-pre$(Ndate)-installer
  78. ifneq "$(SNAPSHOT)" "" set Ifilename putty-$(Date)-installer
  79. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Ifilename putty-custom-$(Date)-installer
  80. # Set up the version string for the Windows installer.
  81. ifneq "$(RELEASE)" "" set Iversion $(RELEASE)
  82. ifneq "$(PRERELEASE)" "" set Iversion $(PRERELEASE)-pre$(Ndate).$(vcsid)
  83. ifneq "$(SNAPSHOT)" "" set Iversion $(Date).$(vcsid)
  84. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" set Iversion Custom-$(Date).$(vcsid)
  85. # Set up the Windows version resource info, for both the installer and
  86. # the individual programs. This must be a sequence of four 16-bit
  87. # integers compared lexicographically, and we define it as follows:
  88. #
  89. # For release X.YY: X.YY.0.0
  90. # For a prerelease before the X.YY release: (X.YY-1).(DDDDD + 0x8000).0
  91. # For a devel snapshot after the X.YY release: X.YY.DDDDD.0
  92. # For a custom build: X.YY.DDDDD.1
  93. #
  94. # where DDDDD is a representation of the build date, in the form of a
  95. # number of days since an epoch date. The epoch is reset at every
  96. # release (which, with 15 bits, gives us a comfortable 80-odd years
  97. # before it becomes vital to make another release to reset the count
  98. # :-).
  99. ifneq "$(RELEASE)" "" in . do echo $(RELEASE).0.0 > winver
  100. ifneq "$(PRERELEASE)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], 0x8000+$$ARGV[1]' $(Lastver) $(Days) > winver
  101. ifneq "$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.0", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
  102. ifeq "$(RELEASE)$(PRERELEASE)$(SNAPSHOT)" "" in . do perl -e 'printf "%s.%d.1", $$ARGV[0], $$ARGV[1]' $(Lastver) $(Days) > winver
  103. in . do perl -pe 'y!.!,!' winver > winvercommas
  104. read Winver winver
  105. read Winvercommas winvercommas
  106. # Write out a version.h that contains the real version number.
  107. in putty do echo '/* Generated by automated build script */' > version.h
  108. ifneq "$(RELEASE)" "" in putty do echo '$#define RELEASE $(RELEASE)' >> version.h
  109. ifneq "$(PRERELEASE)" "" in putty do echo '$#define PRERELEASE $(PRERELEASE)' >> version.h
  110. ifneq "$(SNAPSHOT)" "" in putty do echo '$#define SNAPSHOT' >> version.h
  111. in putty do echo '$#define TEXTVER "$(Textver)"' >> version.h
  112. in putty do echo '$#define SSHVER "$(Sshver)"' >> version.h
  113. in putty do echo '$#define BINARY_VERSION $(Winvercommas)' >> 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.hlp
  125. in putty/doc do make $(Docmakever) chm
  126. # Munge the installer script locally so that it reports the version
  127. # we're really building.
  128. in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(AppVerName=).*$$/$$1$$a/' '$(Puttytextver)' putty.iss
  129. in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(VersionInfoTextVersion=).*$$/$$1$$a/' '$(Textver)' putty.iss
  130. in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(AppVersion=).*$$/$$1$$a/' '$(Iversion)' putty.iss
  131. in putty/windows do perl -i~ -pe 'BEGIN{$$a=shift@ARGV;}s/^(VersionInfoVersion=)\d+\.\d+\.\d+\.\d+\r?$$/$$1$$a/' '$(Winver)' putty.iss
  132. # Windowsify LICENCE, since it's going in the Windows installer.
  133. in putty do perl -i~ -pe 'y/\015//d;s/$$/\015/' LICENCE
  134. # Some gratuitous theming for the MSI installer UI.
  135. in putty/icons do make
  136. 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
  137. in putty do convert -size 493x58 canvas:white \( icons/putty-48.png -geometry +440+5 \) -composite windows/msibanner.bmp
  138. delegate windows
  139. # Build the main binaries.
  140. in putty/windows with visualstudio do/win nmake -f Makefile.vc $(Makeargs) all cleantestprogs
  141. # Code-sign the binaries, if the local bob config provides a script
  142. # to do so. We assume here that the script accepts an -i option to
  143. # provide a 'more info' URL, and an optional -n option to provide a
  144. # program name, and that it can take multiple .exe filename
  145. # arguments and sign them all in place.
  146. ifneq "$(winsigncode)" "" in putty/windows do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/putty/ *.exe
  147. # Ignore exit code from hhc, in favour of seeing whether the .chm
  148. # file was created. (Yuck; but hhc appears to return non-zero
  149. # exit codes on whim.)
  150. in putty/doc with htmlhelp do/win hhc putty.hhp & type putty.chm >nul
  151. # Build the WiX MSI installer.
  152. in putty/windows with wix do/win candle -dWinver="$(Winver)" -dPuttytextver="$(Puttytextver)" installer.wxs && light -ext WixUIExtension -ext WixUtilExtension -sval installer.wixobj
  153. # Build the old Inno Setup installer.
  154. in putty/windows with innosetup do/win iscc putty.iss
  155. # Sign the installers.
  156. ifneq "$(winsigncode)" "" in putty/windows do $(winsigncode) -i http://www.chiark.greenend.org.uk/~sgtatham/putty/ -n "PuTTY Installer" installer.msi Output/installer.exe
  157. # Finished Windows builds.
  158. return putty/windows/*.exe
  159. return putty/windows/*.map
  160. return putty/doc/putty.chm
  161. return putty/windows/installer.msi
  162. return putty/windows/Output/installer.exe
  163. enddelegate
  164. in putty/doc do make mostlyclean
  165. in putty/doc do make $(Docmakever)
  166. in putty/windows do zip -k -j putty.zip `ls *.exe | grep -v puttytel` ../doc/putty.chm ../doc/putty.hlp ../doc/putty.cnt
  167. in putty/doc do zip puttydoc.zip *.html
  168. # Deliver the actual PuTTY release directory into a subdir `putty'.
  169. deliver putty/windows/*.exe putty/x86/$@
  170. deliver putty/windows/putty.zip putty/x86/$@
  171. deliver putty/windows/installer.msi putty/x86/$(Ifilename).msi
  172. deliver putty/windows/Output/installer.exe putty/x86/$(Ifilename).exe
  173. deliver putty/doc/puttydoc.zip putty/$@
  174. deliver putty/doc/putty.chm putty/$@
  175. deliver putty/doc/putty.hlp putty/$@
  176. deliver putty/doc/putty.cnt putty/$@
  177. deliver putty/doc/puttydoc.txt putty/$@
  178. deliver putty/doc/*.html putty/htmldoc/$@
  179. deliver putty/putty-src.zip putty/$@
  180. deliver putty/*.tar.gz putty/$@
  181. # Deliver the map files alongside the `proper' release deliverables.
  182. deliver putty/windows/*.map maps-x86/$@
  183. # Deliver sign.sh, so that whoever has just built PuTTY (the
  184. # snapshot scripts or me, depending) can conveniently sign it with
  185. # whatever key they want.
  186. deliver putty/sign.sh $@
  187. # Create files of cryptographic checksums, which will be signed along
  188. # with the files they verify. We've provided MD5 checksums for a
  189. # while, but now MD5 is looking iffy, we're expanding our selection.
  190. #
  191. # Creating these files is most easily done in the destination
  192. # directory, where all the files we're delivering are already in their
  193. # final relative layout.
  194. in-dest putty do a=`\find * -type f -print`; md5sum $$a > md5sums && sha1sum $$a > sha1sums && sha256sum $$a > sha256sums && sha512sum $$a > sha512sums
  195. # And construct .htaccess files. One in the top-level directory,
  196. # setting the MIME types for Windows help files and providing an
  197. # appropriate link to the source archive:
  198. in-dest putty do echo "AddType application/octet-stream .chm" >> .htaccess
  199. in-dest putty do echo "AddType application/octet-stream .hlp" >> .htaccess
  200. in-dest putty do echo "AddType application/octet-stream .cnt" >> .htaccess
  201. 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
  202. # And one in the x86 directory, providing links for the installers.
  203. in-dest putty/x86 do for ext in msi exe; do set -- putty*installer.$$ext; for k in '' .gpg; do echo RedirectMatch temp '(.*/)'putty-installer.$$ext$$k\$$ '$$1'"$$1$$k" >> .htaccess; done; done