Wikia

Wikihack

Compiling

2,032pages on
this wiki
Talk18

This page contains help on compiling NetHack from source.

On Windows 8.1 with CygwinEdit

  • Make sure the following cygwin packages are installed:

binutils, bison, flex, gcc-g++, libncurses-devel

Change the following lines

#include <curses.h>
#ifndef LINUX
    extern char *tparm();
#endif

to

#ifdef __CYGWIN__
#include <ncurses/curses.h>
#else
#include <curses.h>
#endif
#ifndef LINUX
#ifndef __CYGWIN__
    extern char *tparm();
#endif
#endif
  • Edit include/config.h and change to
COMPRESS "/usr/bin/gzip"
COMPRESS_EXTENSION ".gz"
  • Edit sys/unix/Makefile.utl and change to
LEX = flex
  • Edit sys/unix/Makefile.src and change to
WINTTYLIB = -lncurses
  • Edit sys/unix/Makefile.top and change to
GAMEUID = (your windows username)
GAMEGRP = Users
  • Once the above changes have been made, run the following commands
sh sys/unix/setup.sh
make clean
make
make install

On WindowsEdit

This was tested on: - Win2k with MinGW-5.0.3, - WinXP with MinGW-5.1.1,

NOTE: MinGW version 5.1.1 can be downloaded from: http://download408.mediafire.com/0cnai0w5i85g/ysnyqpdienpjb0z/MinGW-5.1.1.exe

  • Install MinGW. If you use the 'minimal' installation, remember to also select the optional 'MinGW make' -component, so it gets installed. Use, say, C:\mingw\ as the path to install to.
  • Unpack the NetHack source package somewhere, say, c:\nh343\. After unpacking, that directory should contain several subdirectories, such as src, include, win and sys. You will need WinZip or some other utility that can uncompress the package.
  • NOTE: Make sure you do NOT have a shell (e.g. 'sh') on your %PATH% for Windows.
  • Go to c:\nh343\sys\winnt\ and run nhsetup.bat
  • If you want to run the graphical windows GUI, edit c:\nh343\src\makefile.gcc and change the line
#GRAPHICAL=Y

to

GRAPHICAL=Y

NOTE: The latest MinGW (5.1.3 as of writing) has issues compiling the GUI version of the program. To remedy this, copy rpcndr.h from c:\MinGW\include\ to c:\nh343\include\. Edit c:\nh343\include\rpcndr.h by removing or commenting out line 52: "typedef unsigned char boolean;". This should allow the compile to commence with minimal errors.

  • Go to c:\nh343\ and create a new file called 'install.bat' with the following contents:
PATH=c:\mingw\bin
cd src
mingw32-make -f makefile.gcc install
  • Run the install.bat you just created. This takes about thirty seconds.
  • The NetHack binary should now be in c:\nh343\binary\
  • If you want to patch your NetHack, you should next see the article on patching.

On LinuxEdit

TTYEdit

The following compiles the TTY-version of NetHack, with all the default settings.

  • Make sure you have the development packages for ncurses installed. On debian these are called libncurses5-dev. You will also need make, gcc, yacc (or something similar, for example bison), and lex (or something similar, such as flex).
  • Open a terminal, and cd to the directory where you downloaded the source package to.
  • Unpack the NetHack sources and move to the NetHack source root directory:
tar xvzf nethack-343-src.tgz
cd nethack-3.4.3
  • Execute the script that moves the Makefiles to the correct places:
sh sys/unix/setup.sh x
  • Edit include/unixconf.h by changing
/* #define LINUX */

to

#define LINUX
  • Edit src/Makefile by commenting the following like so
#WINTTYLIB = -ltermlib

and uncommenting this line so it looks like

WINTTYLIB = -lncurses
  • If you're using something else than yacc and lex, edit util/Makefile so that YACC and LEX defines are correct.
  • If you are using cygiwn, edit include/config.h and uncomment the following like so
#define STRNCMPI        /* compiler/library has the strncmpi function */
  • Typing make in the NetHack source root dir should compile the binary executable. Typing make all will compile everything, including special levels.
  • To install NetHack to /usr/games/, type make install while you're logged in as root. If you want to change the installation directory, you need to edit the top Makefile.
  • For more information about compiling NetHack, see the sys/unix/Install.unx text file.
  • If you want to patch your NetHack, you should next see the article on patching.

X11Edit

The following compiles the X11 windowport with default settings. First follow the instructions in the TTY section, then continue this.

  • Make sure you have the X11 Athena Widget libraries and headers installed. On Debian the packages are libxaw, libxaw-dev and libxaw-headers.
  • Edit include/config.h by changing
/* #define X11_GRAPHICS */

to

#define X11_GRAPHICS

and

/* # define USE_XPM */

to

# define USE_XPM
  • Edit src/Makefile:
    • add $(WINX11SRC) to WINSRC
    • add $(WINX11OBJ) to WINOBJ
    • add $(WINX11LIB) to WINLIB
    • Change WINX11LIB so that it has -lXaw -lXmu -lXext -lXt -lXpm -lX11 -lm
    • At least on Debian, WINX11LIB also needs -L/usr/X11R6/lib
  • Edit Makefile so that VARDATND includes x11tiles NetHack.ad pet_mark.xbm rip.xpm
  • Type make in the NetHack source root dir.
  • To install NetHack to /usr/games/, type make install while you're logged in as root. If you want to change the installation directory, you need to edit the top Makefile.
  • For more information about compiling NetHack, see the sys/unix/Install.unx text file. For X11 compilation, see win/X11/Install.X11
  • If you want to patch your NetHack, you should next see the article on patching.
  • If you want to use tiles on X11, or change the window colors, see the article on X11 configuration.

On Mac OS XEdit

These are the instructions for compiling a TTY port of NetHack with default settings on Mac OS X. You will need to have the Xcode developer tools installed in order to be able to compile NetHack (check the CDs that came with your copy of Mac OS X). A minimal working knowledge of C and Terminal is assumed.

This has worked on at least OSX 10.6.1, 10.6.8, and 10.8.3.

  1. Download NetHack's sources from http://nethack.org/v343/download-src.html and unpack them.
  2. Open Terminal and cd to Nethack's sys/unix directory. Run sh setup.sh and then return to the root source folder. If you were successful, a new file named Makefile will now be present there, as well as in the src folder.
  3. If you are installing "vanilla" Nethack, read about the problems described at this page on the Nethack wiki and install patch-ac. (Do not do this step for Snow Leopard)
  4. Edit the file include/unixconf.h to make three changes: (Do not do this for Snow Leopard)
    • Uncomment the BSD
  5. define on line 22,
    • Comment out the
  6. defines for SYSV on line 28, and
    • Comment out the
  7. defines for SVR4 on line 35.
  8. In the file win/tty/termcap.c, change line 838 from
  9. ifndef LINUX to
  10. if !defined(LINUX) && !defined(__APPLE__)
  11. Make three changes to the file src/Makefile, which was created in step 2:
    • Uncomment line 233,
    • Comment out line 234
    • On line 154, change CFLAGS = -O -I../include to CFLAGS = -O2 -I../include. (This avoids a fatal error ( mkmaze.c:281: error: unable to find a register to spill in class 'Q_REGS') compiling mkmaze.c.)
  12. cd to the src directory and run make to compile the bulk of NetHack. This should take no more than a couple of minutes. If you needed to install the pkgsrc patch at step 3, you will receive an error here about a conflicting definition of srandom.
  13. Edit the Makefile in the root source directory to fix the game permissions. Here is one solution:
    • Change 'games' on line 20 to 'root',
    • Change 'games' on line 21 to 'staff',
    • Change the value of GAMEPERM on line 25 to 0755
  14. In Terminal, at the top source directory, run make all to create the auxiliary files, and then run sudo make install to install the game.
  15. To install the manpages, edit doc/Makefile by changing the path on line 44 to wherever you wish to install them (create the directory if necessary), and then run make install (or 'make manpages' on Snow Leopard, possibly with sudo) from the doc directory.
  16. Different versions of Mac OS X may have different issues with file permission settings on various components of /usr/games/lib/nethackdir. The following is sufficient for Snow Leopard:
    • $ sudo chmod 775 /usr/games/lib/nethackdir
    • $ sudo chmod 775 /usr/games/lib/nethackdir/save/
    • $ sudo chmod 775 /usr/games/lib/nethackdir/perm
    • $ sudo chmod 775 /usr/games/lib/nethackdir/record
  17. I then got errors on startup and exiting, "No such file or directory. Exec to compress save/501Tartley failed". I fixed this by editing include/config.h, line 172, change to read:
#define COMPRESS "/usr/bin/gzip"
I don't know whether this gzip exists on OSX by default, or whether I had installed it previously (e.g. from some package like "coreutils" in homebrew)

Then play! For example, "ln -s /usr/games/nethack /usr/local/bin" and type "nethack" from a terminal, or type open src/nethack from the top source directory in Terminal.

On iPhone/iPod Touch Edit

This is a tricky setup. The iPhone/iPod Touch (as of firmware 2.1), due to distribution terms, terminal sandboxing, and other odds and ends associated with a highly proprietary product, tends make things difficult.


So, we'll assume that you're using a jailbroken iPhone or iPod Touch for this procedure. We'll also assume that you're looking to play the game locally on the device on the go, as anyone can use the free terminal and telnet software to connect to NAO or equivalent.

We additionally assume that you're compiling for terminal mode; for tiles or native window manager support, far more work will be required in the future.


For compiling on the device itself, you will need:

  • MobileTerminal or OpenSSH
  • GCC, Make, and/or Toolchain 2.0
  • Bison
  • Flex


All of which may be found in Cydia's package repositories or, if you do not have Cydia, various places online.


Due to the rapid state of flux associated with commercial offerings, this list shall not be comprehensive. However, it WILL cover the highlights:


  • SCP or otherwise download the latest sources onto your device, and perform the necessary tar -xzf. We use /usr/games as a candidate location, and /usr/games/nethack-3.4.3 as our top level directory for the remaining steps.


  • Browse into the sys/unix directory and read the associated documentation, to get a good feel for what you'll be doing with your system.


  • (Optional) Alter settings in include/config.h such as compression options, wizard mode, etc. No changes need be made in here, though changing compression options will suppress a rather annoying warning.


  • Return to sys/unix. Open Makefile.top and alter PREFIX, GAME, GAMEUID, GAMEGRP, GAMEDIR, VARDIR, SHELLDIR, and anything else you feel is necessary.


For convenience, here are tested values:

PREFIX   = /usr/games
GAME     = nethack
# GAME     = nethack.prg
GAMEUID  = mobile
GAMEGRP  = wheel
...
GAMEDIR  = /usr/games/lib/$(GAME)dir
VARDIR  = $(GAMEDIR)
SHELLDIR = /bin


  • For the remaining makefiles in sys/unix, add CC = gcc or your compiler to the top of the file. In this example, CC = arm-apple-darwin9-gcc is used. Only Makefile.src and Makefile.utl should be required for this step.
Note: It is suggested, but not currently required, to also include items like:

CFLAGS = -O -I../include -I/var/include
LFLAGS = -L"/usr/lib" -F"/System/Library/Frameworks" -F"/System/Library/PrivateFrameworks" -bind_at_load

... by the maintainer of Toolchain 2.0. 


However, this does not appear to be necessary; nor does alteration of the code of main().


  • From the main directory, specific source edits are required for localization in this environment:
    • win/tty/termcap.c:839: Comment out: // extern char *tparm();
    • sys/unix/Makefile.src:234: Make sure WINTTYLIB is defined as -lncurses instead of -ltermlib or similar.
    • sys/unix/Makefile.utl:108: Set YACC and LEX to use bison and flex, respectively. Example lines for these changes are given within this file.
    • sys/unix/Makefile.doc:23: Set GUIDECMD = cat Guidebook.txt instead of the default.
Note: flex and bison may not work in the current build, stating "Bus error".


If this happens to you, it is advised to make the .c and .h files for this step
on a different system and copy them into /util and /include manually.


  • (2.x firmware) At several steps in the build process, you will need to run ldid to sign each binary file, as unsigned files will be automatically "Killed" by the system with no further information.

To do this, either alter the make files or perform the following incremental steps manually:

ldid -S makedefs  (in util)
ldid -S recover   (in util)
ldid -S dgn_comp  (in util)
ldid -S lev_comp  (in util)
ldid -S nethack   (in src or the final install location (we use /bin))

(ldid should be located in /usr/bin)


  • (Optional) Create your own .nethackrc in your system's user directory (usually /private/var/mobile) and enjoy! :)


Other steps may be required, but these are the major steps that result in a functional, working build of nethack. Of special note, color and lit_corridor does not work in certain local terminals, but otherwise, all Unix options appear to be supported.

Additionally, mobile and root seem to conflict if both users are used interchangeably, causing deaths by trickery. Only one user is advised (preferably the unprivileged mobile) with this current setup.

This test was performed with vanilla NetHack, though there should be no reason for this procedure to fail with many mods, patches, or slashem.

Getting color to work on iPhone/iPod Touch Edit

Of special note is the fact that this build supports color, but this does not appear to enable color within MobileTerminal.app (vt100).

However, color support can be verified by ssh in xterm, or in other terminal software for the iPhone and iPod Touch.

NotesEdit

  • If using flex and 'make' fails with 'Broken Pipe', you'll need to downgrade your version of flex. Version 2.5.4a works with NetHack.
  • By default, the Guidebook isn't copied to the game's directory. You'll need to copy it manually.


Cross building reference notesEdit

May be this can be interesting for developers who want to cross compile this great game:

http://crux-arm.nu/gitweb/?p=ports/games-cross.git;a=blob;f=nethack/Pkgfile;h=4403c9d78cdc20bbc975584e5dd40b52d91f7c4d;hb=c38c624a549d690faef9de02d1a01de4f1267253

Around Wikia's network

Random Wiki