Warren's Notes:
---------------
I currently use the makefile.gcc.  Make sure the BORG is disabled!
My system only includes the base install for Mingw32,  and calls DJGPP's
flex, bison, make, etc.  The compile appears to be ok ;)

Compiling the WinNT Nethack port using gcc (Cygwin or Mingw32)
--------------------------------------------------------------


What Currently Works:

I have successfully compiled Nethack 3.2.2 using Mumit Khan's version of
Mingw32 (a native port of gcc for Windows).  I have gotten this to work with
the distributions based on egcs 1.1.2 as well as gcc-2.95 (the latter being the
most current version at the time of this writing).

For a make utility, I have successfully used GNU make, both Mumit Khan's port
(version 3.77) as well as the make utility supplied with the Cygwin B20.1
distribution (version 3.75 of make).  For the latter, MAKE_MODE must be set to
UNIX (see below for details).


What Doesn't (yet) Work:

I haven't been able to build Nethack using egcs 1.1 from the Cygwin
distribution (a virtual UNIX enviroment for Windows systems).  Also, my
makefile does not currently work correctly when compiling from bash or any
other UNIX shell.

I have done some work in both of these areas, so if you would like to get
either or both of these to work, see the "Using Cygwin" section
below.

Finally, my makefile runs into problems when trying to use the data librarian.
If you would like to try to get this to work, change USE_DLB = N to
USE_DLB = Y in my makefile.


Required Tools:

To get Nethack to build successfully using my makefile, you currently need the
following tools:

 * Windows 95, 98 or NT
 * Mingw32 (gcc for Windows) compiler
 * A GNU make utility
 * Some version of yacc/bison and lex/flex
 * UNIX echo utility

As mentioned previously, the most current version of Mingw32  is based on the
gcc 2.95 compiler, and is available at:

ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95/

Download gcc-2.95-mingw32.zip from there, and read the INSTALL file in that
same directory for installation instructions.

For a GNU make utility, you can either use Mumit Khan's port of make for
Mingw32, or use the make utility supplied with the full Cygwin distribution.
For the Mingw32 version of make, go to:

ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/ports/make-3.77-mingw32.zip

Be sure to place make.exe in the bin directory under your Mingw32 directory, or
somewhere else in your PATH.

Bison, flex and the UNIX echo utility are all part of the full Cygwin
distribution as well.  There may be other ports of these tools available, but
these were the ones I used.  To install the Cygwin distribution, download
full.exe from Cygnus's FTP site or a mirror, and run the executable to install.

Note that the bin directory will have to be in the system PATH before
attempting to compile so the tools needed can be called from the makefile.
Download sites for Cygwin are listed at:

http://sourceware.cygnus.com/cygwin/download.html

Finally, of course, you will need the makefile itself.  A zip file containing
the makefile as well as these instructions can be found at:

http://home.earthlink.net/~karlgarrison/nethack/gnu-win32/nhgwin32.zip


Build Instructions:

Once your tools are setup properly, you should be ready to build.  Download the
sources for Nethack 3.2.2, place the makefile.g32 file in the src directory,
and rename it to makefile.

Note (Warren):  The makefile I use for compiling with Mingw32 using DJGPP
make, bison, yacc is there as makefile.gcc

After choosing a makefile, the sources should compile with no problems.  You may
want to look at the makefile to see if there is anything you wish to change.
In particular, look at the variable GAMEDIR.  By default, the game will install
to a directory named \games\nethackd on the current drive.  This directory
should exist before compiling, and it should be empty.  You may change this to
a different directory if you wish, but I'm not certain if specifying a
different drive letter will work.

Finally, if you are using the Cygwin version of make, you will need to set the
enviroment variable MAKE_MODE to UNIX so that the makefile is read properly:

SET MAKE_MODE=UNIX

Now, from your DOS prompt, change to the src directory, and type:

make install

After some time, the game should be compiled and installed in the
\games\nethackd directory or whatever directory you specified.  Happy Hacking!


Using Cygwin:

As mentioned previously, I have not been able to compile successfully using
the compiler supplied with the Cygwin B20.1 distribution.  I have, however,
done some work in this area, so if you wish to get this to work, you may want
to build off of what I have already done.  I have added checks for Cygwin to
config.h, system.h and ntconf.h in the include directory.  You can either copy
the modified versions of these files included in the zipfile with my makefile,
or make the changes manually as described below.  I would recommend making the
changes manually if you wish to contribute to this port so you can see what has
been changed:

changes to config.h:

Here we need to add a check for Cygwin in order to define WIN32 (which is
auto-defined by other Win32 compilers, but not Cygwin).  Also, other Win32
compilers need the STRNCMPI define, but it should not be defined for Cygwin.

In config.h, look for the following block of code (should start on line 113):

#ifdef WIN32
# undef UNIX
# undef MSDOS
# define STRNCMPI
#endif

Above this block of code, add the following lines:

#ifdef __CYGWIN__
# define WIN32  /* Cygwin compiler does not define WIN32 */
#endif

Within the block of code, add a check for Cygwin to make certain STRNCMPI is
not defined.  After modification, the block will look like this:

#ifdef WIN32
# undef UNIX
# undef MSDOS
# ifndef __CYGWIN__
#  define STRNCMPI
# endif
#endif

Changes to system.h:

In this file we add 3 checks for Cygwin to avoid conflicting declarations.

On line 79 of system.h, look for the following line:

# if !defined(__SC__)

Change this to look like the following:

# if !defined(__SC__) && !defined(__CYGWIN__)

A few lines below, on line 85, look for the following:

#  if !defined(bsdi) && !defined(LINUX)

Change it so that it reads:

#  if !defined(bsdi) && !defined(LINUX) && !defined(__CYGWIN__)

Finally, on line 183, look for the following:

# if (defined(BSD) || defined(ULTRIX)) && !defined(LINUX)

Change this to:

# if (defined(BSD) || defined(ULTRIX)) && (!defined(LINUX) && !defined(__CYGWIN__))

Changes to ntconf.h:

In ntconf.h I add a check for Cygwin so that it will not try to include the
non-existant conio.h file.  It is likely that this will cause problems later
when the code tries to use functions defined in conio.h, but at least it will
allow us to get farther and see what functions are needed from this file and
use another approach.

In ntconf.h, look for the following line (should be line 77):

#include <conio.h>

Change this so this file is not included if we are compiling with Cygwin:

#ifndef __CYGWIN__
# include <conio.h>
#endif

Once the source changes have been made, copy the makefile.g32 to the src
directory and rename it to makefile.  Edit makefile in a text editor, change
the S variable (seperator) to / rather than \\, and set the COPY, DEL, and
ECHO utilities to UNIX versions of these commands (cp for copy, rm -f for rm,
and echo.exe for echo).  Also, check the GAMEDIR variable, and make certain
the directory specified exists, and is empty.  By default, the makefile will
try to install to /games/nethackd on the same drive you are attempting to
compile.

At ths point you can attempt to compile by changing to the src directory from
your Cygwin bash prompt and type "make" or "make install".  Typing just
"make" will build only nethack.exe, whereas "make install" will compile level
files, etc before building the game, then copy everything to the game
directory.

In reality, neither of these actions get that far.  When building
nethack.exe, you will run into numerous compiler errors when it attempts to
compile the output of bison.  I'm not certain what the cause is; the same
output seems to work fine when compiled with Mingw32.  This is where someone
more familiar with Cygwin may be able to pick-up where I left off.

When running "make install", you will get a number of makefile-related
problems when it attempts to compile and copy level files, etc.  This shows
that I did an imperfect job of making my makefile work with both a UNIX shell
and a DOS prompt.  If soeone is able to fix this, I hope they do it in a way
so that compiling with just a DOS prompt still works.  I would perfer to have
1 makefile support both if possible, but if not perhaps there will have to be
seperate Cygwin and Mingw32 makefiles.

As a final note, if you make any progress in either of these areas, please
let me know, and send your changes to me so I can update this information.
My email address is at the bottom of this document.


Related Links:

Explaination of Cygwin, Mingw32, gcc, egcs, etc.:

http://www.xraylith.wisc.edu/~khan/software/gnu-win32/

Cygwin homepage:

http://sourceware.cygnus.com/cygwin/

Nethack 3.2.2 sources as 1 big zip file:

http://www.nohotdogbuns.com/~jthilo/NetHack/nh322.zip



Karl Garrison
karlgarrison@earthlink.net

October 25, 1999
