NetHack/Building

Free Reference for NetHack

Tutorial

Spoilers

Edit this template

NetHack has several different build systems because its source code can be made to run on several different operating systems.

You might want to build NetHack yourself, to make customisations such as enabling wizard mode.

Unix

edit
 

To do:


NetHack has no GNU configure script. It is difficult to build on Unix platforms because it often makes incorrect assumptions about the system. If you want to build it, this book assumes that you are familiar with the Unix shell prompt, including the "make" command, "cc" command, and the options "-I", "-L", and "-l" of "cc".

After extracting NetHack, look at sys/unix/Install.unx. That file contains the instructions. This book only gives an example of how to use vendor patches to build a NetHack with tty, X11, and Qt support in one binary.

Vendor Patches

edit

However, many Unix and Linux distros contain NetHack. It helps to obtain the patches used by your Unix or Linux vendor. This skips over the step where we modify Makefiles and header files to describe the Unix variant that we use.

For example, on OpenBSD, NetHack and patches are available in the ports tree.

$ cd /usr/ports/games/nethack
$ make configure

The above command performs the following steps, if necessary:

$ fetch NetHack source code from the Internet
$ extract source code from archive
$ patch source code with build settings for OpenBSD
$ configure (copy patched Makefiles into place)

In fact, since we have the patches, we probably also have the script for building. Continuing from above, we could make build or make install and have a copy of NetHack very similar to the binary package provided by the OS vendor.

However, one can make customisations. First move the source directory out of the ports tree:

$ mv w-nethack-3.4.3/nethack-3.4.3/ /some/path

The sources, already configured and ready to build, appear at /some/path/nethack-3.4.3.

Enabling the Windowing Systems

edit

A windowing system, from the NetHack point of view, is code that allows NetHack to show itself on the screen. On Unix, these systems are available:

  • tty: The traditional code which draws NetHack using ASCII characters on a terminal. If you like to play NetHack in an xterm or over telnet, then you need this.
  • X11: A graphical version of NetHack using the X Window System and the Xaw widgets.
  • Qt: Another X11 version, but using the Qt widgets
Requirements
edit
  • tty: You need curses and termcap/terminfo, but you already have them ("vi" or "nano" uses them). If you used your OS vendor patches, then your NetHack is already configured to build with the curses and termlib found on your system.
  • X11: You need X Window System and Xaw. Using XFree86 or Xorg includes everything you need.
  • Qt: You need Qt version 2 or 3. The sources say version 2, but version 3 seems to work.

To enable these environments, some #defines must be set in include/config.h. It is also possible to just use "-D" options to the compiler.

Several things in the Makefiles must be adjusted to support the different window systems. It might be easiest to create a "config" file of "make" variables, then copy the variable assignments into Makefile, src/Makefile, and util/Makefile.

OpenBSD had a setup where these three files automatically included a config file:

Bourne shell
$ export NETHACKCONFIG=/path/to/config 

C shell
$ setenv NETHACKCONFIG /path/to/config 

This is a merger of OpenBSD's X11 and Qt configs, designed to support both in one binary:

# installation
PREFIX = /usr/local
NHDIR = /usr/local/lib/nethackdir-3.4.3

# compiler
CC = cc
CXX = c++
LINKCMD = c++ -pthread
MOC = moc3

# graphics for X11 and Qt
VARDATND = x11tiles pet_mark.xbm rip.xpm

# compile and link flags
QTDIR = /usr/local
CFLAGS += -pthread -DX11_GRAPHICS -DQT_GRAPHICS
CFLAGS += -DDEFAULT_WINDOW_SYS=\"tty\" -I/usr/local/include/X11/qt3
CFLAGS += -I/usr/X11R6/include -I/usr/local/include
LFLAGS = -L/usr/local/lib/qt3 -L/usr/X11R6/lib -L/usr/local/lib

# objects
WINSRC = $(WINTTYSRC) $(WINX11SRC) $(WINQTSRC)
WINOBJ = $(WINTTYOBJ) $(WINX11OBJ) qt_win.o qt_clust.o qttableview.o
WINLIB = $(WINTTYLIB) $(WINX11LIB) -lqt-mt -lSM

To use this on other systems, one must make some adjustments. The variable "LINKCMD" (instead of "LINK") and "NHDIR" are specific to OpenBSD, having been introduced by the vendor patches. Examine your vendor patches and determine which are the correct variables to set.

To set variables like "MOC" that are already set in some Makefile, the other setting must be commented with "#".

Build

edit

A build is normally like

$ make all
$ make install