NetHack/Building

From StrategyWiki, the free strategy guide and walkthrough wiki

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 enable wizard mode, to play with patches, or for other reasons. This chapter is about how to do that. If you installed a prebuilt binary, as most players do, or you play on a telnet server, then feel free to skip this chapter.

Contents

[edit] Window ports

Before you build NetHack, you should decide which window ports you want.

  • tty: The traditional ASCII, no-graphics port for your Unix terminal or DOS prompt. If you like to play NetHack in an xterm or over telnet, then you need this.
  • Qt: (for Mac and Unix) A graphical port using Trolltech's Qt library. NetHack wants Qt 2, but Qt 3 seems to work. We do not know whether Qt 4 will work.
  • win32: A "native" window port for Microsoft Windows.
  • mac: A "native" window port for the Macintosh.

Unix users can also try the X11 graphical port, but it requires much difficult runtime configuration. Do stay away from the gnome port; it requires version 1 of libgnome and libgnomeui, but nearly everyone has version 2.

[edit] Windows

For Windows builds consult http://nethack.wikia.com/wiki/Compiling

[edit] Unix

You can build NetHack on Unix systems, including *BSD, GNU/Linux, and Mac OS X.

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, then it helps to be familiar with the Unix shell prompt, including the "make" command, "cc" command, and the options "-I", "-L", and "-l" of "cc".

The official instructions are in sys/unix/Install.unx after extracting NetHack.

[edit] Vendor patches

Many Unix and Linux distros already contain NetHack. In many cases you can examine the patches from your Unix or Linux vendor. These patches can give hints on how to configure NetHack for your system. There are patches for:

Hopefully this page will tell you what you need to know, and you will not need to study the vendor patches.

[edit] Configuring your source code

  1. If your NetHack sources are in an archive, extract them. Examples:
    • zcat nethack-3.4.3.tgz | pax -rv && cd nethack-3.4.3
    • mkdir nethack-3.4.3 && cd nethack-3.4.3 && unzip ../nh343.zip
  2. Apply patches. Example:
    • patch -p1 < dump-343.diff
  3. Run sys/unix/setup.sh to extract the Makefiles.
    • cd sys/unix && sh setup.sh && cd ../..
  4. Edit include/config.h. You will define (remove the /* ... */) some configurations to enable them, while you comment (add the /* ... */) configurations to disable them.
    • In section 1, UNIX should already be on. If you want Qt, define QT_GRPAHICS and maybe comment TTY_GRAPHICS.
    • In section 2, change both occurrences of "wizard" to your username, so you can play in wizard/debug mode! Define DLB, it works well upon Unix. Change HACKDIR to where you want the playground. If this is your personal installation (you are not becoming root to install NetHack), then HACKDIR should be somewhere in your home directory.
    • In section 3, define VISION_TABLES (unless you run some embedded Unix and need to save space).
    • In sections 4 and 5, define SCORE_ON_BOTL and AUTOPICKUP_EXCEPTIONS to enable more runtime options. Do whatever else you want to do.
  5. Edit include/unixconf.h.
    • Do not define BSD. Modern *BSD folk (including Mac OS X) should keep the default SYSV, SVR4, POSIX_JOB_CONTROL, and POSIX_TYPES! (Defining BSD enables bad random/srandom declarations in include/system.h from lines 75 and 92, and your game might fail to compile.)
    • Enable LINUX if you run Linux (for better random numbers, random/srandom not lrand48/srand48).
    • Disable MAIL if you want.
  6. Edit src/Makefile. You will define things by removing the # in front or comment things by adding the #.
    • Your make probably already defines MAKE and CC.
    • Scroll down past the commented CFLAGS and LFLAGS examples to the default "CFLAGS = -O -I../include" and "LFLAGS =" lines. They should work on most modern systems. If your cc is gcc (true with *BSD, GNU/Linux, Mac OS X) then you can change "-O" to "-O2" (hyphen, capital letter O, number 2), like in the Linux example.
    • Set WINTTYLIB correctly. Mac OS X needs "WINTTYLIB = -lncurses". Upon OpenBSD, you might as well use -lcurses, though -ltermlib will work because it is a deprecated synonym.
    • If building the Qt port, then make sure to adjust the WINSRC, WINOBJ, and WINLIB lines to for example "WINSRC = $(WINTTYSRC) $(WINQTSRC)" or "WINSRC = $(WINQTSRC)", and make sure the Qt settings are in order. Add "-I/usr/X11R6/include -I/usr/local/include" to CFLAGS and "-L/usr/X11R6/lib -L/usr/local/lib" to LFLAGS if necessary.
  7. Edit util/Makefile to set CFLAGS and LFLAGS like in src/Makefile.
  8. Edit Makefile, the top level one.
    • Set GAME to name your executable; "nethack" is fine, but not if you are doing multiple builds!
    • Set GAMEDIR to match your HACKDIR in include/config.h. During install, NetHack will delete everything in GAMEDIR/HACKDIR, so make sure that there are no files there except unwanted old versions of NetHack.
    • Set SHELLDIR to a place for the "nethack" executable, like /usr/local/bin or $(HOME)/bin.
    • Set up permissions. If you are installing into your home directory, then just set "CHOWN = true" and "CHGRP = true" to make everything belong to you.

[edit] Build

A build is normally like

$ make all
$ make install     # or sudo make install on Mac OS X