Buildscr 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # -*- sh -*-
  2. # Build script to build Puzzles.
  3. #
  4. # You can cut out large components of the build by defining a subset
  5. # of these options on the bob command line:
  6. # -DNOTEST -DNOSIGN -DNOWINDOWS -DNOMACOS -DNOICONS -DNOJAVA -DNOJS
  7. module puzzles
  8. set Version $(!builddate).$(vcsid)
  9. # Put the version number into the documentation as a versionid.
  10. # use perl to avoid inconsistent behaviour of echo '\v'
  11. in puzzles do perl -e 'print "\n\\versionid Simon Tatham'\''s Portable Puzzle Collection, version $$ARGV[0]\n"' $(Version) >> puzzles.but
  12. in puzzles do perl -e 'print "\n\\versionid Simon Tatham'\''s Portable Puzzle Collection, version $$ARGV[0]\n"' $(Version) >> devel.but
  13. # Write out a version.h that contains the real version number.
  14. in puzzles do echo '/* Generated by automated build script */' > version.h
  15. in puzzles do echo '$#define VER "Version $(Version)"' >> version.h
  16. # And do the same substitution in the OS X metadata. (This is a bit
  17. # icky in principle because it presumes that my version numbers don't
  18. # need XML escaping, but frankly, if they ever do then I should fix
  19. # them!)
  20. in puzzles do perl -i -pe 's/Unidentified build/$(Version)/' osx/Info.plist
  21. # And in the KaiOS metadata generator.
  22. in puzzles do perl -i -pe 's/Unidentified build/$(Version)/' kaios/manifest.pl
  23. ifneq "$(NOICONS)" yes then
  24. # Run enough of a native Unix build to produce the various icons.
  25. # This also checks that the build completes in 'strict' mode (with
  26. # lots of warnings and -Werror), and triggers a build failure if
  27. # not.
  28. in . do cmake -B build-icons puzzles -DSTRICT=ON
  29. in build-icons do make -j$(nproc)
  30. in build-icons do make -j$(nproc) icons VERBOSE=1
  31. # Copy the C icon files into the icons source subdirectory, for the
  32. # distribution tarball.
  33. in . do cp build-icons/icons/*-icon.c puzzles/icons
  34. endif
  35. ifneq "$(NOTEST)" yes then
  36. # Run tests. In particular, ensure we build in 'strict' mode with
  37. # both gcc and clang.
  38. ifeq "$(NOICONS)" yes then
  39. # We don't need to run the gcc build if we did it above for the icons
  40. in . do cmake -B test-gcc puzzles -DSTRICT=ON
  41. in test-gcc do make -j$(nproc)
  42. endif
  43. in . do cmake -B test-clang puzzles -DSTRICT=ON -DCMAKE_C_COMPILER=clang
  44. in test-clang do make -j$(nproc)
  45. endif
  46. # The very first thing we do is to make the source archive, before we
  47. # fill up the build directory with extra files.
  48. delegate -
  49. # Build Windows Help and text versions of the manual for convenience.
  50. in puzzles do halibut --winhelp=puzzles.hlp --text=puzzles.txt puzzles.but
  51. # Build a text version of the HACKING document.
  52. in puzzles do halibut --text=HACKING devel.but
  53. # Get rid of some cruft that isn't really useful in a source tarball.
  54. in puzzles do rm -f Buildscr CHECKLST.txt .gitignore webpage.pl
  55. in . do ln -s puzzles puzzles-$(Version)
  56. in . do tar -chzf puzzles-$(Version).tar.gz puzzles-$(Version)
  57. return puzzles-$(Version).tar.gz
  58. enddelegate
  59. ifneq "$(NOMACOS)" yes then
  60. # Build the OS X binaries and .dmg archive.
  61. delegate osx
  62. in puzzles do cmake -B build-osx -DCMAKE_BUILD_TYPE=Release .
  63. in puzzles/build-osx do make -j$(nproc) package VERBOSE=1
  64. return puzzles/build-osx/Puzzles.dmg
  65. enddelegate
  66. endif
  67. ifneq "$(NOWINDOWS)" yes then
  68. # Build the Windows binaries and installer, and the CHM file.
  69. in puzzles do make -f Makefile.doc clean
  70. in puzzles do make -f Makefile.doc -j$(nproc) # build help files for installer
  71. in . with cmake_at_least_3.20 do cmake -B puzzles/build-win64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_TOOLCHAIN_FILE=$(cmake_toolchain_clangcl64) -DICO_DIR=$$PWD/build-icons/icons puzzles
  72. in . with cmake_at_least_3.20 do cmake -B puzzles/build-win32 -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_TOOLCHAIN_FILE=$(cmake_toolchain_clangcl32) -DICO_DIR=$$PWD/build-icons/icons puzzles
  73. in puzzles/build-win64 do make -j$(nproc) VERBOSE=1
  74. in puzzles/build-win32 do make -j$(nproc) VERBOSE=1
  75. in puzzles do mason.pl --args '{"version":"$(Version)","descfile":"build-win64/gamedesc.txt"}' winwix.mc > puzzles.wxs
  76. # Code-sign the binaries, if the local bob config provides a script
  77. # to do so. We assume here that the script accepts an -i option to
  78. # provide a 'more info' URL, and an optional -n option to provide a
  79. # program name, and that it can take multiple .exe filename
  80. # arguments and sign them all in place.
  81. ifneq "$(cross_winsigncode)" "" in puzzles do $(cross_winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/puzzles/ build-win64/*.exe build-win32/*.exe
  82. # Build installers.
  83. in puzzles with wixonlinux do candle -arch x64 puzzles.wxs -dWin64=yes -dBindir=build-win64/ && light -ext WixUIExtension -sval puzzles.wixobj
  84. in puzzles with wixonlinux do candle -arch x86 puzzles.wxs -dWin64=no -dBindir=build-win32/ && light -ext WixUIExtension -sval puzzles.wixobj -o puzzles32.msi
  85. ifneq "$(cross_winsigncode)" "" in puzzles do $(cross_winsigncode) -i https://www.chiark.greenend.org.uk/~sgtatham/puzzles/ -n "Simon Tatham's Portable Puzzle Collection Installer" puzzles.msi puzzles32.msi
  86. in puzzles do chmod +x build-win32/*.exe build-win64/*.exe
  87. endif
  88. # Build the HTML docs.
  89. in puzzles do mkdir doc
  90. in puzzles do mkdir devel
  91. in puzzles/doc do halibut --html -Chtml-contents-filename:index.html -Chtml-index-filename:indexpage.html -Chtml-template-filename:%k.html -Chtml-template-fragment:%k ../puzzles.but
  92. in puzzles/devel do halibut --html -Chtml-contents-filename:index.html -Chtml-index-filename:indexpage.html -Chtml-template-filename:%k.html -Chtml-template-fragment:%k ../devel.but
  93. ifneq "$(NOWINDOWS)" yes then
  94. # Move the deliver-worthy Windows binaries (those specified in
  95. # gamedesc.txt, which is generated by CMakeLists.txt and helpfully
  96. # excludes the command-line auxiliary utilities such as solosolver,
  97. # and nullgame.exe) into a subdirectory for easy access.
  98. in puzzles do mkdir winbin64 winbin32
  99. in puzzles/build-win64 do mv `cut -f2 -d: gamedesc.txt` ../winbin64
  100. in puzzles/build-win32 do mv `cut -f2 -d: gamedesc.txt` ../winbin32
  101. # Make a zip file of the Windows binaries and help files.
  102. in puzzles do zip -j puzzles.zip winbin64/*.exe puzzles.chm puzzles.hlp puzzles.cnt
  103. in puzzles do zip -j puzzles32.zip winbin32/*.exe puzzles.chm puzzles.hlp puzzles.cnt
  104. endif
  105. # Build the autogenerated pieces of the main web page.
  106. in puzzles do cmake -B build-gamedesc . -DCMAKE_TOOLCHAIN_FILE=../cmake/windows-dummy-toolchain.cmake
  107. in puzzles do perl webpage.pl build-gamedesc/gamedesc.txt
  108. # Group is playable, even if still a bit unpolished and strange, so we
  109. # can at least make the web versions of it (which are unobtrusive if
  110. # you don't deliberately navigate to the web pages).
  111. set web_unfinished_option -DPUZZLES_ENABLE_UNFINISHED=group
  112. ifneq "$(NOJAVA)" yes then
  113. # Build the Java applets.
  114. delegate nestedvm
  115. in puzzles do cmake -B build-nestedvm -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/nestedvm-toolchain.cmake -DNESTEDVM="$$NESTEDVM" $(web_unfinished_option) .
  116. in puzzles/build-nestedvm do make -j$(nproc) VERBOSE=1
  117. return puzzles/build-nestedvm/*.jar
  118. return puzzles/build-nestedvm/unfinished/group.jar
  119. enddelegate
  120. endif
  121. # Build the Javascript applets. Since my master build machine doesn't
  122. # have the right dependencies installed for Emscripten, I do this by a
  123. # delegation.
  124. ifneq "$(NOJS)" yes then
  125. # The Emscripten delegate doesn't have Halibut, so build a set of
  126. # HTML docs for the KaiOS apps to use.
  127. in puzzles do mkdir -p build-kaios/help/en
  128. in puzzles/build-kaios/help/en do halibut --html -Chtml-template-fragment:%k ../../../puzzles.but ../../../emcccopy.but
  129. delegate emscripten
  130. in puzzles do emcmake cmake -B build-emscripten $(web_unfinished_option) .
  131. in puzzles/build-emscripten do make -j$(nproc) VERBOSE=1
  132. return puzzles/build-emscripten/*.js
  133. return puzzles/build-emscripten/*.wasm
  134. return puzzles/build-emscripten/unfinished/group.js
  135. return puzzles/build-emscripten/unfinished/group.wasm
  136. in puzzles do emcmake cmake -B build-kaios -DWASM=NO -DICON_DIR=$$PWD/../build-icons/icons -DCMAKE_BUILD_TYPE=Release .
  137. in puzzles/build-kaios do make -j$(nproc) VERBOSE=1 install
  138. in puzzles/build-kaios/kaios do for p in *; do (cd $$p && zip -rDn .png ../$$p.zip *); done
  139. return puzzles/build-kaios/kaios/*.zip
  140. enddelegate
  141. # Build a set of wrapping HTML pages for easy testing of the
  142. # Javascript puzzles.
  143. #
  144. # These aren't quite the same as the HTML pages that will go on my
  145. # live website. The live ones will substitute in a different footer
  146. # that links back to the main puzzles page, and they'll have a
  147. # different filesystem layout so that ther links to the .js files
  148. # won't need the ../js/ prefix used below.
  149. #
  150. # But these test pages should be good enough to just open after
  151. # running a build, to make sure the main functionality works.
  152. # Unfortunately, because JavaScript can't read arbitrary local
  153. # files, this won't usually work from a file:// URL. You have to
  154. # either point an HTTP or HTTPS server at the build output directory
  155. # or turn off security.fileuri.strict_origin_policy in Firefox.
  156. in puzzles do mkdir jstest
  157. in puzzles/jstest do ../html/jspage.pl --jspath=../js/ /dev/null ../html/*.html
  158. endif
  159. # Set up .htaccess containing a redirect for the archive filename.
  160. in puzzles do echo "AddType application/octet-stream .chm" > .htaccess
  161. in puzzles do echo "AddType application/octet-stream .hlp" >> .htaccess
  162. in puzzles do echo "AddType application/octet-stream .cnt" >> .htaccess
  163. in puzzles do echo "AddType application/wasm .wasm" >> .htaccess
  164. in . do set -- puzzles*.tar.gz; echo RedirectMatch temp '(.*/)'puzzles.tar.gz '$$1'"$$1" >> puzzles/.htaccess
  165. in puzzles do echo RedirectMatch temp '(.*/)'puzzles-installer.msi '$$1'puzzles-$(Version)-installer.msi >> .htaccess
  166. # Phew, we're done. Deliver everything!
  167. ifneq "$(NOICONS)" yes then
  168. deliver build-icons/icons/*-web.png $@
  169. endif
  170. ifneq "$(NOWINDOWS)" yes then
  171. deliver puzzles/winbin64/*.exe $@
  172. deliver puzzles/winbin32/*.exe w32/$@
  173. deliver puzzles/puzzles.zip $@
  174. deliver puzzles/puzzles32.zip w32/$@
  175. deliver puzzles/puzzles.msi puzzles-$(Version)-installer.msi
  176. deliver puzzles/puzzles32.msi w32/puzzles-$(Version)-32bit-installer.msi
  177. deliver puzzles/puzzles.chm $@
  178. deliver puzzles/puzzles.hlp $@
  179. deliver puzzles/puzzles.cnt $@
  180. endif
  181. deliver puzzles/.htaccess $@
  182. deliver puzzles/doc/*.html doc/$@
  183. deliver puzzles/devel/*.html devel/$@
  184. ifneq "$(NOMACOS)" yes then
  185. deliver puzzles/build-osx/Puzzles.dmg $@
  186. endif
  187. ifneq "$(NOJAVA)" yes then
  188. deliver puzzles/build-nestedvm/*.jar java/$@
  189. deliver puzzles/build-nestedvm/unfinished/*.jar java/$@
  190. endif
  191. ifneq "$(NOJS)" yes then
  192. deliver puzzles/build-emscripten/*.js js/$@
  193. deliver puzzles/build-emscripten/*.wasm js/$@
  194. deliver puzzles/build-emscripten/unfinished/*.js js/$@
  195. deliver puzzles/build-emscripten/unfinished/*.wasm js/$@
  196. deliver puzzles/jstest/*.html jstest/$@
  197. deliver puzzles/html/*.html html/$@
  198. deliver puzzles/html/*.pl html/$@
  199. deliver puzzles/build-kaios/kaios/*.zip kaios/$@
  200. ifneq "$(NOICONS)" yes then
  201. deliver build-icons/icons/*-banner.jpg kaios/$@
  202. endif
  203. endif
  204. deliver puzzles/wwwspans.html $@
  205. deliver puzzles/wwwlinks.html $@
  206. # deliver puzzles/puzzles.armv4.cab $@ # (not built at the moment)
  207. # This one isn't in the puzzles subdir, because makedist.sh left it
  208. # one level up.
  209. deliver puzzles*.tar.gz $@