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.

270 lines
11 KiB

2 years ago
2 years ago
2 years ago
2 years ago
17 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. NetHack Porting Guidelines v 3.7 2019-12-05
  2. 1.0 Introduction
  3. This document goes through the steps required to port NetHack to a
  4. new machine. The basic steps in porting the program are:
  5. 1. Get the code onto your build machine. The parts of the current
  6. directory setup you definitely need include src (NetHack code
  7. shared by all systems), include (include files), util (code
  8. for utility programs), and dat (various data files). The
  9. documentation in doc is strongly recommended. You already
  10. have the files in the top directory since you're reading this
  11. one. :-)
  12. If you will be cross-compiling for your target platform on
  13. a different platform, you may want to read Cross-compiling
  14. in the Top folder as well.
  15. A full list of the distribution files and their associated
  16. OSes may be found in the top-level file "Files".
  17. If your machine uses an OS already supported, you need the sys
  18. subdirectory for that OS and possibly sys/share. Otherwise,
  19. get the closest match (say sys/msdos for single-tasking OSes
  20. and sys/unix for multi-user OSes, along with sys/share, if
  21. nothing else comes to mind). You may want others for
  22. comparison.
  23. If your machine uses a windowing system already supported,
  24. you need the win subdirectory for that system (or the
  25. appropriate sys subdirectory if the windowing system was
  26. previously considered restricted to one OS) and possibly
  27. win/share.
  28. 2. Modify the appropriate include files to customize NetHack to
  29. your system. You may need to add a new OS-specific "*conf.h"
  30. file (see unixconf.h, pcconf.h, tosconf.h, etc. as examples).
  31. 3. If your machine uses a new OS instead of a variant of existing
  32. OSes, add a new sys subdirectory. Add, if required, a OS-
  33. specific copy of "main.c", "tty.c" and "unix.c". Possibly
  34. add an OS-specific library (see "msdos.c" and "tos.c" as
  35. examples) to provide functions NetHack wants and your OS lacks.
  36. 4. If your machine uses a new windowing system, follow doc/window.doc
  37. carefully. Put files implementing these routines in a win or
  38. sys subdirectory as appropriate.
  39. 5. If your compilation environment isn't close to one already
  40. supported, try starting from the UNIX makefiles. Modify the
  41. top level makefile and the src makefile as required. Then run
  42. an initial compile. You are bound to get some errors. You
  43. should be able to fix them in a fairly simple fashion. If
  44. things seem to be getting too complex, take a step back, and
  45. possibly send us some mail. We might be able to help.
  46. 6. Mail all of your fixes to us in a contextual form so that we can
  47. easily integrate them into the code, or fork the NetHack
  48. repository on GitHub and issue a pull-request for your changes.
  49. One general rule of thumb exists. Always add code. Don't delete
  50. somebody else's code for yours -- it won't work on their machine if you do.
  51. Always add your OS specific code inside #ifdef / #else / #endif constructs
  52. so that it will be able to be folded back into the original code easily.
  53. 2.0 Include Files
  54. 2.1 config.h
  55. The file "config.h" is a master configuration file that determines
  56. the basic features of the game, as well as many of the security options.
  57. It is intended that end users configure the game by editing "config.h" and
  58. an appropriate "*conf.h" file, so any #defines for individual preferences
  59. should be added to those files. OS-specific #defines that are not intended
  60. to be changed should also go in "*conf.h"; try to find the most appropriate
  61. place for other #defines.
  62. The following sections may require modification:
  63. - Section 1: OS and window system selection.
  64. You may have to put a #define for your OS here.
  65. If your OS is yet another UNIX variant, put the
  66. #define in unixconf.h instead.
  67. An unfortunately large amount of stuff shares
  68. this section because the #definitions have to
  69. be seen before *conf.h is reached. Don't add
  70. to this unless necessary.
  71. - Section 2: Global parameters and filenames.
  72. These will have to be customized to your system.
  73. - Section 3: Type definitions and other compiler behavior.
  74. These will have to be matched to your compiler.
  75. 2.2 global.h
  76. This file defines things specific to NetHack that should not
  77. require modification by an end user. For a new port, you may have to add
  78. automatic inclusion of another auxiliary config file (*conf.h) which you
  79. wrote for your system.
  80. 2.3 extern.h
  81. If you create any new source modules or new functions in old modules,
  82. you must enter the names of the new external references (the functions defined
  83. there for external use) in this file.
  84. 2.4 system.h
  85. This file contains references for all hooks into the OS (via the
  86. standard "C" libraries). Depending on what your standard library looks like,
  87. you may have to put new entries into this file.
  88. 3.0 Source files
  89. The first step in getting the game up is to get the "makedefs"
  90. program running. This program is used to create configuration-specific
  91. files for the game.
  92. Once "makedefs" has been built, the rest of the game can be compiled.
  93. You may have to create an OS-specific module to handle things you want to
  94. use, like a mouse or a ram-disk.
  95. 3.1 Makefiles
  96. This distribution provides makefiles for several kinds of systems.
  97. There are joint makefiles for the various varieties of UNIX, makefiles for
  98. MSDOS, a makefile for NT, and so on. You may have to create a new
  99. makefile for your specific machine. You may even have to translate some
  100. makefiles into a form more congenial to your system. If possible, however,
  101. add to one of those provided.
  102. 3.2 termcap.c
  103. If your system wants to use tty windowing and it doesn't run off
  104. of a termcap or terminfo database, you may have to put the appropriate
  105. terminal control strings into termcap.c. This has already been done for
  106. MSDOS, and these mods can be used as an example. You can also consider
  107. using the termcap code from sys/share/tclib.c or sys/share/termcap.uu,
  108. especially if your system supports multiple kinds of terminals.
  109. 3.3 main.c
  110. You may need to create a new "main.c" module. If you do, call it
  111. [OS]main.c where the [OS] is replaced with the name of the OS you are porting
  112. to. This file contains the mainline module, which reads options from the
  113. command line (or wherever) and processes them. It also contains various
  114. functions associated with game startup.
  115. 3.4 tty.c
  116. You may need to create a new "tty.c" module. If you do, call it
  117. [OS]tty.c where the [OS] is replaced with the name of the OS you are porting
  118. to. This file contains the routines that configure the terminal/console
  119. for raw I/O, etc.
  120. 3.5 unix.c
  121. You may need to create a new "unix.c" module. If you do, call it
  122. [OS]unix.c where the [OS] is replaced with the name of the OS you are porting
  123. to. This file contains some OS dependencies concerning time and filename
  124. creation.
  125. An object of the NetHack development project is to get the game
  126. working on as many different types of hardware and under as many different
  127. operating systems as is practical. Any assistance will be appreciated.
  128. Cross-compiling may allow porting of NetHack to a machine where there may
  129. be challenges building on the platform directly, and may help maintain a
  130. working version of NetHack on that platform. See the file Cross-compiling
  131. for more information.
  132. 4.0 Build Process
  133. NetHack requires the following steps to be carried out:
  134. 4.1. makedefs
  135. Compile and link util/makedefs. Run makedefs repeatedly with different command
  136. line options to produce several output files that are required for:
  137. (a) additional build steps to follow, including some header
  138. files: pm.h, onames.h, date.h.
  139. (b) creation of files, containing information required by,
  140. or about the game during its execution, that are stored in a
  141. portable, platform-independent way, that need to be inserted
  142. into the final game package.
  143. util/makedefs -v
  144. util/makedefs -o
  145. util/makedefs -p
  146. util/makedefs -d
  147. util/makedefs -r
  148. util/makedefs -h
  149. util/makedefs -s
  150. 4.2. Other utilities
  151. Compile and link other utilities such as uudecode, tile-generation
  152. utilities, and so forth. Those produce output files for use during the game and
  153. need to be included in the packaging of the game.
  154. 4.3. Lua
  155. Compile and link into a library, or obtain a prebuilt Lua library for
  156. your platform. Place the Lua source into lib/lua-5.4.3 (or other folder
  157. representing an appropriate Lua version); place the compiled Lua library into
  158. lib.
  159. 4.4 Compile NetHack sources
  160. Compile the source code of the game, including a suitable
  161. regular-expression choice from several options available in sys/share. Pick one
  162. that is supported by your OS or that you have obtained a 3rd party library for.
  163. 4.5 Compile optional window port components into a library
  164. If your platform requires 3rd party sources in order to support the
  165. window port options that you have chosen, such as curses sources for the curses
  166. window port, you may store the sources for that library in a subfolder under
  167. lib.
  168. 4.6. Link the game
  169. Link the game to the Lua library, and to any window port support
  170. libraries.
  171. 4.7 Package the game
  172. 5.0 Design Updates
  173. The following design updates were introduced in NetHack 3.7.
  174. 5.1 Quest text files
  175. The quest text files that were formerly converted from their source
  176. text by makedefs during the build process, have been replaced by Lua versions
  177. and are inserted into the game package for processing by the embedded Lua
  178. interpreter during game execution.
  179. 5.2 Level Compiler
  180. There is no longer a build-time level compiler. Instead, the level
  181. descriptions have been converted to Lua and are inserted into the game package
  182. for processing by the embeded Lua interpreter during game execution.
  183. 5.3 Dungeon Compiler
  184. There is no longer a build-time dungeon compiler. Instead, the dungeon
  185. description has been converted to Lua and is inserted into the game package for
  186. processing by the embeded Lua interpreter during game execution.
  187. 5.4 Run-time Options
  188. Some of the build and option information that was formerly produced at
  189. build-time by makedefs, and contained information about the game platform and
  190. options selected during the build of the game can now be produced at run-time
  191. by code within the game itself. That was done to facilitate cross-compiling of
  192. NetHack on one platform for game execution on another.
  193. # NetHack 3.7 Porting $NHDT-Date: 1596498144 2020/08/03 23:42:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.9 $
  194. # Copyright (c) 2005 by Michael Allison
  195. # NetHack may be freely redistributed. See license for details.