NetHack; the official development repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
11 KiB

expand sys/unix Makefiles scope Expand the use of the sys/unix Makefiles to be used for both normal local builds and installs, as well as cross-compiles for other platforms/targets. Up until now, the primary unix Makefiles have treated util/host-side component compiles, links and target object files just the same as the game component compiles, links, and target object files. Unfortunately, that meant that cross-compile effort typically had to re-invent Makefiles specific to the cross-compile, creating a maintenance burden and deviation from the typical local unix build and providing a daunting obstacle to those that want to establish build for a target environment/platform. This change distinguishes between util/host-side component builds, links, and component builds and targets object files destined for the game (and other target platforms) in the Makefiles. In theory, this will ease the effort for people that want to try to resurrect NetHack perhaps on an old platform where it is no longer viable to build NetHack-3.7 on the platform itself using old, outdated compile tools, possibly with an old, outdated C dialect. Some details: - Game-related targets in the Makefiles (as opposed to util/host-side targets that will be executed on the host), which could be destined for another platform in a cross-compile scenario are prefixed with $(TARGETPFX) so that they are distinguished. The default scenario where no cross-compiler is involved, is to define TARGETPFX to nothing, and therefore meant to have no effect. - Game-related compile and link commands in the Makefiles and their associated command line flags are distinguished from util/host-side compile and link commands in the Makefiles by using $(TARGET_CC), $(TARGET_CFLAGS), $(TARGET_LINK), $(TARGET_LFLAGS), $(TARGET_CXX), $(TARGET_CXXFLAGS), $(TARGET_LIBS). Those are used in the Makefile in place of $(CC), $(CFLAGS), $(LINK), $(LFLAGS), $(CXX), $(CXXFLAGS), $(LIBS). The default scenario where no cross-compiler is involved, defines the TARGET_ version of those Makefile variables to match their typical non-TARGET_ ounterparts. - The dependency lists in the Makefiles includes the $(TARGETPFX) prefix for stuff that would potentially be produced from a cross-compile build. - It adds pregame targets and $(PREGAME) variable, so that hints files can add some additional stuff if required for a cross-compile scenario. The default scenario where no cross-compiler is involved doesn't do anything for $(PREGAME). - It adds $(BUILDMORE) target and variable, so that hints files can add some additional things to be built for a cross-compile scenario. - It adds a "package" target and $(PACKAGE) variable, so that hints files can add steps for the target platform in a cross-compile scenario. The "install" target assumes local build and placement and isn't really applicable to a cross-compile scenario where the results really just need to be bundled up for transport to the target platform. - Also, this adds a pair of include files that can be updated with some cross-compile recipes as they evolve. They are named "cross-pre.2020" (for stuff to be included in the PRE section) and "cross-post.2020" for stuff to be included in the POST section via sys/unix/setup.sh. Those are included in sys/unix/hints/linux.2020 and sys/unix/hints/macOS.2020 hints files.
1 year ago
  1. # NetHack Top-level Makefile.
  2. # NetHack 3.7 Makefile.top $NHDT-Date: 1609702004 2021/01/03 19:26:44 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.66 $
  3. # Copyright (c) 2015 by Kenneth Lorber, Kensington, Maryland
  4. # NetHack may be freely redistributed. See license for details.
  5. # Root of source tree: (Note: dot is after setup.sh has been used
  6. # to create the active Makefiles from sys/unix/Makefile.*.
  7. # It isn't sys/unix/ where you might happen to be reading this.)
  8. NHSROOT=.
  9. # Newer makes predefine $(MAKE) to 'make' and do smarter processing
  10. # of recursive make calls if $(MAKE) is used.
  11. # These makes allow $(MAKE) to be overridden by the environment if
  12. # someone wants to (or has to) use something other than the standard
  13. # make, so we do not want to unconditionally set $(MAKE) here.
  14. #
  15. # Unfortunately, some older makes do not predefine $(MAKE); if you
  16. # have one of these, uncomment the following line.
  17. # (You will know that you have one if you get complaints about unable
  18. # to execute things like 'data' and 'rumors'.)
  19. # MAKE = make
  20. # make NetHack (as opposite to variants or such)
  21. #PREFIX = /usr
  22. GAME = nethack
  23. # GAME = nethack.exe
  24. # GAME = nethack.prg
  25. #GAMEUID = games
  26. #GAMEGRP = bin
  27. # Permissions - some places use setgid instead of setuid, for instance.
  28. # See also the option "SECURE" in include/config.h.
  29. #GAMEPERM = 04755
  30. FILEPERM = 0644
  31. # VARFILEPERM = 0644
  32. EXEPERM = 0755
  33. DIRPERM = 0755
  34. # VARDIRPERM = 0755
  35. # VARDIR may also appear in unixconf.h as "VAR_PLAYGROUND" else HACKDIR
  36. #
  37. # Note well! 'make install' believes in creating a nice tidy HACKDIR
  38. # for installation, free of debris from previous NetHack versions --
  39. # therefore there should not be anything in HACKDIR that you want to
  40. # keep (if there is, you'll have to do the installation by hand or
  41. # modify the install commands below).
  42. #HACKDIR = $(PREFIX)/games/lib/$(GAME)dir
  43. #VARDIR = $(HACKDIR)
  44. # Where nethack.sh is installed (as 'nethack').
  45. # If this is not defined, the shell wrapper script is not used.
  46. #SHELLDIR = $(PREFIX)/games
  47. # Extra data files depending upon the interface(s) built into nethack.
  48. # per discussion in Install.X11 and Install.Qt
  49. # Qt prefers nhtiles.bmp but can use x11tiles, and it ignores NetHack.ad.
  50. # X11 uses those last two.
  51. # Both can display a convential text map instead of tiles.
  52. # tty and/or curses (no extra data files outside of the dlb container):
  53. #VARDATND =
  54. # All X11 and/or Qt variations may also include tty or curses or both):
  55. # X11 without Qt:
  56. # VARDATND = x11tiles NetHack.ad pet_mark.xbm pilemark.xbm
  57. # X11 with GRAPHIC_TOMBSTONE (requires 'xpm'):
  58. # VARDATND = x11tiles NetHack.ad pet_mark.xbm pilemark.xbm rip.xpm
  59. # both X11 and Qt:
  60. # VARDATND = x11tiles nhtiles.bmp NetHack.ad pet_mark.xbm pilemark.xbm rip.xpm
  61. # Qt without X11; assumes GRAPHIC_TOMBSTONE:
  62. # VARDATND = nhtiles.bmp pet_mark.xbm pilemark.xbm rip.xpm
  63. VARDATD = bogusmon data engrave epitaph oracles options quest.lua rumors
  64. VARDAT = $(VARDATD) $(VARDATND)
  65. # Some versions of make use the SHELL environment variable as the
  66. # shell for running commands. We need this to be a Bourne shell.
  67. # SHELL = /bin/sh
  68. # for Atari (obsolete)
  69. # SHELL=E:/GEMINI2/MUPFEL.TTP
  70. # Commands for setting the owner and group on files during installation.
  71. # Some systems fail with one or the other when installing over NFS or for
  72. # other permission-related reasons. If that happens, you may want to set the
  73. # command to "true", which is a no-op. Note that disabling chown or chgrp
  74. # will only work if setuid (or setgid) behavior is not desired or required.
  75. #CHOWN = chown
  76. #CHGRP = chgrp
  77. # Lua version
  78. LUA_VERSION = 5.4.3
  79. #
  80. # end of configuration
  81. #
  82. DATHELP = help hh cmdhelp keyhelp history opthelp wizhelp
  83. SPEC_LEVS = asmodeus.lua baalz.lua bigrm-*.lua castle.lua fakewiz?.lua \
  84. juiblex.lua knox.lua medusa-?.lua minend-?.lua minefill.lua \
  85. minetn-?.lua oracle.lua orcus.lua sanctum.lua soko?-?.lua \
  86. tower?.lua valley.lua wizard?.lua nhcore.lua nhlib.lua themerms.lua \
  87. astral.lua air.lua earth.lua fire.lua water.lua
  88. QUEST_LEVS = ???-goal.lua ???-fil?.lua ???-loca.lua ???-strt.lua
  89. DATNODLB = $(VARDATND) license symbols
  90. DATDLB = $(DATHELP) dungeon.lua tribute $(SPEC_LEVS) $(QUEST_LEVS) $(VARDATD)
  91. DAT = $(DATNODLB) $(DATDLB)
  92. TOPLUALIB = lib/lua/liblua.a
  93. ALLDEP = $(GAME) recover Guidebook $(VARDAT) spec_levs check-dlb
  94. # first target is also the default target for 'make' without any arguments
  95. all: $(ALLDEP)
  96. true; $(MOREALL)
  97. @echo "Done."
  98. $(GAME): lua_support
  99. ( cd src ; $(MAKE) $(GAME) )
  100. lua_support: $(TOPLUALIB) include/nhlua.h
  101. @true
  102. lib/lua-$(LUA_VERSION)/src/liblua.a: lib/lua-$(LUA_VERSION)/src/lua.h
  103. ( cd lib/lua-$(LUA_VERSION)/src \
  104. && make CC='$(CC)' SYSCFLAGS='$(SYSCFLAGS)' a && cd ../../.. )
  105. lib/lua/liblua.a: lib/lua-$(LUA_VERSION)/src/liblua.a
  106. @( if [ ! -d lib/lua ] ; then mkdir -p lib/lua ; fi )
  107. cp lib/lua-$(LUA_VERSION)/src/liblua.a $@
  108. include/nhlua.h: $(TOPLUALIB)
  109. echo '/* nhlua.h - generated by top Makefile */' > $@
  110. @echo '#include "../lib/lua-$(LUA_VERSION)/src/lua.h"' >> $@
  111. @sed -e '/(lua_error)/!d' -e '/(lua_error)/s/;/ NORETURN;/1' \
  112. < lib/lua-$(LUA_VERSION)/src/lua.h >> $@
  113. @echo '#include "../lib/lua-$(LUA_VERSION)/src/lualib.h"' >> $@
  114. @echo '#include "../lib/lua-$(LUA_VERSION)/src/lauxlib.h"' >> $@
  115. @echo '/*nhlua.h*/' >> $@
  116. lib/lua-$(LUA_VERSION)/src/lua.h:
  117. echo "Please do 'make fetch-lua' to obtain lua-$(LUA_VERSION)"
  118. false
  119. # Note: many of the dependencies below are here to allow parallel make
  120. # to generate valid output
  121. Guidebook:
  122. ( cd doc ; $(MAKE) Guidebook )
  123. manpages:
  124. ( cd doc ; $(MAKE) manpages )
  125. data: $(GAME)
  126. ( cd dat ; $(MAKE) data )
  127. engrave: $(GAME)
  128. ( cd dat ; $(MAKE) engrave )
  129. bogusmon: $(GAME)
  130. ( cd dat ; $(MAKE) bogusmon )
  131. epitaph: $(GAME)
  132. ( cd dat ; $(MAKE) epitaph )
  133. rumors: $(GAME)
  134. ( cd dat ; $(MAKE) rumors )
  135. oracles: $(GAME)
  136. ( cd dat ; $(MAKE) oracles )
  137. # Note: options should have already been made with make, but...
  138. options: $(GAME)
  139. ( cd dat ; $(MAKE) options )
  140. quest.lua: $(GAME)
  141. spec_levs:
  142. ( cd dat ; $(MAKE) spec_levs )
  143. ( cd dat ; $(MAKE) quest_levs )
  144. nhtiles.bmp: $(GAME)
  145. ( cd util ; $(MAKE) tile2bmp )
  146. ( cd dat ; $(MAKE) nhtiles.bmp )
  147. x11tiles: $(GAME)
  148. ( cd util ; $(MAKE) tile2x11 )
  149. ( cd dat ; $(MAKE) x11tiles )
  150. # obsolete
  151. beostiles: $(GAME)
  152. ( cd util ; $(MAKE) tile2beos )
  153. ( cd dat ; $(MAKE) beostiles )
  154. NetHack.ad: $(GAME)
  155. ( cd dat ; $(MAKE) NetHack.ad )
  156. pet_mark.xbm:
  157. ( cd dat ; $(MAKE) pet_mark.xbm )
  158. pilemark.xbm:
  159. ( cd dat ; $(MAKE) pilemark.xbm )
  160. rip.xpm:
  161. ( cd dat ; $(MAKE) rip.xpm )
  162. mapbg.xpm:
  163. (cd dat ; $(MAKE) mapbg.xpm )
  164. nhsplash.xpm:
  165. ( cd dat ; $(MAKE) nhsplash.xpm )
  166. nh16.img: $(GAME)
  167. ( cd util ; $(MAKE) tile2img.ttp )
  168. ( cd dat ; $(MAKE) nh16.img )
  169. rip.img:
  170. ( cd util ; $(MAKE) xpm2img.ttp )
  171. ( cd dat ; $(MAKE) rip.img )
  172. GEM_RSC.RSC:
  173. ( cd dat ; $(MAKE) GEM_RSC.RSC )
  174. title.img:
  175. ( cd dat ; $(MAKE) title.img )
  176. check-dlb: options
  177. @if egrep -s librarian dat/options ; then $(MAKE) dlb ; else true ; fi
  178. dlb:
  179. ( cd util ; $(MAKE) dlb )
  180. ( cd dat ; LC_ALL=C ; ../util/dlb cf nhdat $(DATDLB) )
  181. wasm:
  182. ( cd src ; $(MAKE) CROSS_TO_WASM=1 ../targets/wasm/nethack.js )
  183. package: $(GAME) recover $(VARDAT) spec_levs
  184. ( cd src ; $(MAKE) $(PACKAGE) )
  185. # recover can be used when INSURANCE is defined in include/config.h
  186. # and the checkpoint option is true
  187. recover: $(GAME)
  188. ( cd util ; $(MAKE) recover )
  189. dofiles:
  190. target=`sed -n \
  191. -e '/librarian/{' \
  192. -e 's/.*/dlb/p' \
  193. -e 'q' \
  194. -e '}' \
  195. -e '$$s/.*/nodlb/p' < dat/options` ; \
  196. $(MAKE) dofiles-$${target-nodlb}
  197. cp src/$(GAME) $(INSTDIR)
  198. cp util/recover $(INSTDIR)
  199. -if test -n '$(SHELLDIR)'; then rm -f $(SHELLDIR)/$(GAME); fi
  200. if test -n '$(SHELLDIR)'; then \
  201. sed -e 's;/usr/games/lib/nethackdir;$(HACKDIR);' \
  202. -e 's;HACKDIR/nethack;HACKDIR/$(GAME);' \
  203. < sys/unix/nethack.sh \
  204. > $(SHELLDIR)/$(GAME) ; fi
  205. # set up their permissions
  206. -( cd $(INSTDIR) ; $(CHOWN) $(GAMEUID) $(GAME) recover ; \
  207. $(CHGRP) $(GAMEGRP) $(GAME) recover )
  208. chmod $(GAMEPERM) $(INSTDIR)/$(GAME)
  209. chmod $(EXEPERM) $(INSTDIR)/recover
  210. -if test -n '$(SHELLDIR)'; then \
  211. $(CHOWN) $(GAMEUID) $(SHELLDIR)/$(GAME); fi
  212. if test -n '$(SHELLDIR)'; then \
  213. $(CHGRP) $(GAMEGRP) $(SHELLDIR)/$(GAME); \
  214. chmod $(EXEPERM) $(SHELLDIR)/$(GAME); fi
  215. dofiles-dlb: check-dlb
  216. ( cd dat ; cp nhdat $(DATNODLB) $(INSTDIR) )
  217. # set up their permissions
  218. -( cd $(INSTDIR) ; $(CHOWN) $(GAMEUID) nhdat $(DATNODLB) ; \
  219. $(CHGRP) $(GAMEGRP) nhdat $(DATNODLB) ; \
  220. chmod $(FILEPERM) nhdat $(DATNODLB) )
  221. dofiles-nodlb:
  222. # copy over the game files
  223. ( cd dat ; cp $(DAT) $(INSTDIR) )
  224. # set up their permissions
  225. -( cd $(INSTDIR) ; $(CHOWN) $(GAMEUID) $(DAT) ; \
  226. $(CHGRP) $(GAMEGRP) $(DAT) ; \
  227. chmod $(FILEPERM) $(DAT) )
  228. #
  229. # This is not part of the dependency build hierarchy.
  230. # It requires an explicit "make fetch-Lua".
  231. fetch-lua: fetch-Lua
  232. @true
  233. fetch-Lua:
  234. ( mkdir -p lib && cd lib && \
  235. curl -R -O http://www.lua.org/ftp/lua-$(LUA_VERSION).tar.gz && \
  236. tar zxf lua-$(LUA_VERSION).tar.gz && \
  237. rm -f lua-$(LUA_VERSION).tar.gz )
  238. #if we just fetched lua, force include/nhlua.h to be built based on it
  239. -rm include/nhlua.h
  240. # 'make update' can be used to install a revised version after making
  241. # customizations or such. Unlike 'make install', it doesn't delete everything
  242. # from the target directory to have a clean start.
  243. update: $(GAME) recover $(VARDAT) spec_levs
  244. # (don't yank the old version out from under people who're playing it)
  245. -mv $(INSTDIR)/$(GAME) $(INSTDIR)/$(GAME).old
  246. -mv $(INSTDIR)/nhdat $(INSTDIR)/nhdat.old
  247. # set up new versions of the game files
  248. ( $(MAKE) dofiles )
  249. # should already be present, but make sure
  250. touch $(VARDIR)/perm $(VARDIR)/record
  251. # and a reminder
  252. @echo You may also want to install the man pages via the doc Makefile.
  253. rootcheck:
  254. @true; $(ROOTCHECK)
  255. install: rootcheck $(GAME) recover $(VARDAT) spec_levs
  256. true; $(PREINSTALL)
  257. # set up the directories
  258. # not all mkdirs have -p; those that don't will create a -p directory
  259. -if test -n '$(SHELLDIR)'; then \
  260. mkdir -p $(SHELLDIR); fi
  261. rm -rf $(INSTDIR) $(VARDIR)
  262. -mkdir -p $(INSTDIR) $(VARDIR) $(VARDIR)/save
  263. if test -d ./-p; then rmdir ./-p; fi
  264. -$(CHOWN) $(GAMEUID) $(INSTDIR) $(VARDIR) $(VARDIR)/save
  265. $(CHGRP) $(GAMEGRP) $(INSTDIR) $(VARDIR) $(VARDIR)/save
  266. # order counts here:
  267. chmod $(DIRPERM) $(INSTDIR)
  268. chmod $(VARDIRPERM) $(VARDIR) $(VARDIR)/save
  269. # set up the game files
  270. ( $(MAKE) dofiles )
  271. # set up some additional files
  272. touch $(VARDIR)/perm $(VARDIR)/record $(VARDIR)/logfile $(VARDIR)/xlogfile
  273. -( cd $(VARDIR) ; $(CHOWN) $(GAMEUID) perm record logfile xlogfile ; \
  274. $(CHGRP) $(GAMEGRP) perm record logfile xlogfile ; \
  275. chmod $(VARFILEPERM) perm record logfile xlogfile )
  276. true; $(POSTINSTALL)
  277. # and a reminder
  278. @echo You may also want to reinstall the man pages via the doc Makefile.
  279. # 'make clean' removes all the .o files, but leaves around all the executables
  280. # and compiled data files
  281. clean: clean-lib clean-keep-lib
  282. @true
  283. clean-lib:
  284. -( cd lib/lua-$(LUA_VERSION)/src && $(MAKE) clean )
  285. clean-keep-lib:
  286. ( cd src ; $(MAKE) clean )
  287. ( cd util ; $(MAKE) clean )
  288. ( cd dat ; $(MAKE) clean )
  289. ( cd doc ; $(MAKE) clean )
  290. # 'make spotless' returns the source tree to near-distribution condition.
  291. # it removes .o files, executables, and compiled data files
  292. spotless:: spotless-lib spotless-keep-lib
  293. @true
  294. spotless-lib:: clean-lib
  295. -( cd lib/lua && rm liblua.a )
  296. spotless-keep-lib: clean-keep-lib
  297. ( cd src ; $(MAKE) spotless )
  298. ( cd util ; $(MAKE) spotless )
  299. ( cd dat ; $(MAKE) spotless )
  300. ( cd doc ; $(MAKE) spotless )