Compiling

From NetHackWiki
Revision as of 16:14, 17 March 2008 by Paxed (talk | contribs) (On Linux: also needed: make, gcc, yacc/bison, lex/flex)
Jump to navigation Jump to search

This page contains help on compiling NetHack from source.

On Windows

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

  • 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.
  • 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 Linux

TTY

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 bison, lex or 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
  • Typing make in the NetHack source root dir should compile the binary executable.
  • 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.

X11

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 X

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). Also, these instructions assume that you have a minimal working knowledge of C and Terminal, and little elaboration will be given.

  • Open Terminal and cd to the sys/unix directory in the source folder. Run sh setup.sh and then return to the root source folder.
  • Edit the file include/unixconf.h by uncommenting the BSD #define on line 22 and commenting out the #defines for SYSV (line 28) and SVR4 (line 35).
  • In the file win/tty/termcap.c, change line 838 from
#ifndef LINUX

to

#if !defined(LINUX) && !defined(__APPLE__)
  • In the file src/Makefile, uncomment line 233 and comment out line 234.
  • cd to the src directory and run make to compile the bulk of NetHack. This should take no more than a couple of minutes.
  • Edit the Makefile in the root source directory by changing 'games' on line 20 to 'root' and 'bin' on line 21 to 'staff'. Then change the values of GAMEPERM on line 25 to 0755, FILEPERM on line 26 to 0664, and DIRPERM on line 28 to 0775. Note that this is just one possible way to configure the game permissions.
  • In Terminal, at the top source directory, run make to create the auxiliary files, and then run sudo make install to install the game.
  • 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 (possibly with sudo) from the doc directory.
  • Play!