NetHack! It’s simply the most fun you can have with letters! Well, I mean, unless you count reading.
Below is a list of steps to compile the open-source game NetHack from the C source code.
1. Download and install MinGW. MinGW is short for “Minimalist GNU for Windows”, and it incorporates “gcc”, which is short for the “GNU Compiler Collection”. While there’s a lot of documentation on the mingw.org website that’s intended to explain how to install and use it, in practice it’s extremely difficult to figure out how to even download it, much less install it. As of this writing, what I believe to be the latest installer is available at “http://sourceforge.net/projects/mingw/?source=dlp”. (UPDATE 2013/09/06 – Upon attempting to run through these steps again, I found installing MinGW to be even more painful than I remembered. The good news is that I eventually found something called “TDM-GCC“, by “John E.”. It appears to be a much simpler way to install MinGW, and I am totally into that.)
2. Download and install Notepad++. Notepad++ is a popular free text and code editor, with a lot of useful features. In this article, it will be used to view text files with Unix-formatted line breaks, and to find and replace text in many source code files at once. As of this writing, the latest version of the installer is available at “http://notepad-plus-plus.org/download/v6.2.2.html”.
3. Download and install 7-Zip, if necessary. 7-Zip is a popular free file compression/decompression utility that understands a lot of file formats, including the “.tgz” format that the NetHack source code is packaged with. As of this writing, the installer for the latest version is available at “http://www.7-zip.org/download.html”.
4. Download the NetHack source code. As of this writing, the source code is available as “nethack-343-src.tgz” at “http://www.nethack.org/v343/download-src.html”.
5. In any convenient directory, use a file decompression tool (7-Zip, perhaps) to extract the source code from the archive file “nethack-343-src.tgz”. You may have to do this twice, since uncompressing the “.tgz” format produces a “.tar” file, which must itself then be extracted to obtain the actual files.
6. In the newly uncompressed nethack-3.4.3 directory, navigate to the sys/winnt directory.
7. Execute the file “nhsetup.bat”. New directories named “binary” and “build” will be added to the nethack-3.4.3 root directory.
8. Open Notepad++.
9. In Notepad++, select the “Search – Find in Files” item from the top menu bar. The “Find in Files” dialog will appear.
10. On the Find in Files dialog, in the “Find what” box, enter the value “boolean”. In the “Replace with” box, enter the value “boolnh”. In the Directory box, enter the path of the newly extracted directory containing the nethack source code files. Activate the “Match Case” checkbox. Activate the “In all sub-folders” checkbox.
11. Still on the Find in Files dialog, click the “Replace in Files” button and then click OK on the confirmation dialog that appears. This will replace all occurrences of the text “boolean” in the NetHack source code with “boolnh”. (This step is necessary to work around a naming conflict that stems from the fact that the NetHack source code is, frankly, elderly.)
12. Open src/makefile.gcc in Notepad++. Comment out the line “DEBUG = Y”. Save the file.
13. Add the path of MinGW’s “bin” directory to the Windows “Path” environment variable. By default, this directory’s path is “C:\MinGW\bin”. (There are multiple ways to access the environment variables. One way is to enter “SystemPropertiesAdvanced.exe” at the Run prompt and click the Environment Variables button on the dialog that appears.)
14. In the root NetHack directory, create a new text file named NetHack-Build.bat, containing the following text.
echo About to attempt make... del /Q binary\*.* cd src del /Q o\*.* mingw32-make -f Makefile.gcc install cd .. echo Make attempt finished. pause
15. Run Nethack-Build.bat. The source code will be compiled, and an executable called NetHack.exe will be created in the “binary” directory.
- This tutorial only shows how to build the text-based version of the game, not the one that uses graphical tiles. The code for that version includes a bunch of stuff that seems to be meant to build the tile images from included text files. I wasn’t immediately able to figure it out, but if you care about graphics, you might want to investigate more closely.
- Similarly, there may be a more elegant and efficient solution to all that stuff about renaming “boolean” to “boolnh”, but again, I couldn’t immediately figure it out. If the documentation for things like this were a little more idiot-friendly, this post (and indeed this blog) might not exist.