# NetHack/Building

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

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

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.
The above command performs the following steps, if necessary:
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:
The sources, already configured and ready to build, appear at /some/path/nethack-3.4.3.

#### Enabling the Windowing Systems

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

* 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:
This is a merger of OpenBSD's X11 and Qt configs, designed to support both in one binary:
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

A build is normally like