# NetHack 3.6	Makefile.gcc	$NHDT-Date: 1434804544 2015/06/20 12:49:04 $  $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.53 $
#
#==============================================================================
#
#   Win32 Compilers Tested:
#                  === TDM-GCC Compiler Suite for Windows ===
#                  ---        GCC 4.6 & 4.7 Series        ---
#                  ***   Standard MinGW 32-bit Edition    ***
#
#   If you don't have this compiler, you can get it at:
#		http://tdm-gcc.tdragon.net/
#
#==============================================================================
#   This is used for building two versions of NetHack:
#
#   A tty port utilizing the Win32 Console I/O subsystem, Console
#       NetHack.
#
#   A Win32 native port built on the Windows API, Graphical NetHack or
#       NetHackW.
#
#   In addition to your C compiler,
#
#     if you want to change     you will need a
#     files with suffix         workalike for
#         .y                     yacc   (such as bison)
#         .l                     lex    (such as flex)
#
#   If you have any questions read the sys/winnt/Install.nt file included
#   with the distribution.
#==============================================================================
# BUILD DECISIONS SECTION
#
# There are currently only 3 decisions that you have to make.
#	1. 32-bit or 64-bit?
#	2. Where do you want your build to end up?
#	3. Do you want debug information in the executable?
#
#==============================================================================
# 1. 32-bit or 64-bit?
#

# 64 bit
#TARGET_CPU=x64
#
# 32 bit
TARGET_CPU=x86
#
#---------------------------------------------------------------
# 2. Where do you want the game to be built (which folder)?
#    If not present prior to compilation it gets created.
#

GAMEDIR = ../binary

#
#---------------------------------------------------------------
# 3. Do you want debug information in the executable?
#

DEBUGINFO = Y

# This marks the end of the BUILD DECISIONS section.
#==============================================================================
#
#===============================================
#======= End of Modification Section ===========
#===============================================
#
################################################
#                                              #
# Nothing below here should have to be changed.#
#                                              #
################################################

#
#  Source directories.    Makedefs hardcodes these, don't change them.
#

# NetHack include files
INCL  = ../include
# NetHack data files
DAT   = ../dat
# NetHack documentation files
DOC   = ../doc
# Utility source
UTIL  = ../util
# Main source
SRC   = ../src
# Shared system files
SSYS  = ../sys/share
# NT Win32 specific files
MSWSYS = ../sys/winnt
# window port files (tty)
TTY   = ../win/tty
# window port files (WIN32)
MSWIN = ../win/win32
# Tile support files
WSHR  = ../win/share

#
#  Object directory.
#

OBJ = o

cc     = gcc
rc     = windres
link   = gcc

#
#==========================================
# Level Compiler Info
#==========================================

# Yacc/Lex ... if you got 'em.
#
# If you have yacc and lex programs (or work-alike such as bison
# and flex), comment out the upper two macros and uncomment
# the lower two.
#

DO_YACC = YACC_MSG
DO_LEX  = LEX_MSG
#DO_YACC  = YACC_ACT
#DO_LEX   = LEX_ACT

# - Specify your yacc and lex programs (or work-alikes) here.

#YACC   = bison -y
YACC   = byacc
#YACC   = yacc

#LEX    = lex
LEX     = flex

#
# - Specify your flex skeleton file (if needed).
#

FLEXSKEL =
#FLEXSKEL = -S../tools/flex.ske

YTABC   = y_tab.c
YTABH   = y_tab.h
LEXYYC  = lexyy.c

#==========================================
# Exe File Info.
#==========================================
#
# Optional high-quality BSD random number generation routines
# (see pcconf.h). Set to nothing if not used.
#

RANDOM  = $(OBJ)/random.o
#RANDOM =

WINPFLAG   = -DTILES -DMSWIN_GRAPHICS -DWIN32CON -D_WIN32_IE=0x0400 -D_WIN32_WINNT=0x0501
# To store all the level files,
# help files, etc. in a single library file.
# USE_DLB = Y is left uncommented

USE_DLB = Y

ifeq  "$(USE_DLB)" "Y"
DLBFLG = -DDLB
else
DLBFLG =
endif

#==========================================
# Setting up the compiler and linker
# macros. All builds include the base ones.
#==========================================
cflags = -mms-bitfields
lflags  =
ifeq  "$(DEBUGINFO)" "Y"
cdebug = -g
linkdebug = -g
else
cdebug =
linkdebug =
endif



CFLAGSBASE  = -c $(cflags) -I$(INCL) $(WINPINC) $(cdebug)
#LFLAGSBASEC = $(linkdebug)
#LFLAGSBASEG = $(linkdebug) -mwindows

conlibs = -lwinmm
guilibs = -lcomctl32 -lwinmm

#==========================================
# Util builds
#==========================================

CFLAGSU = $(CFLAGSBASE) $(WINPFLAG) $(DLBFLG)
LFLAGSU = $(LFLAGSBASEC)

#==========================================
# - Game build
#==========================================

CFLAGS   = $(CFLAGSBASE) $(WINPFLAG) $(DLBFLG)
lflags  = $(LFLAGSBASEC) $(linkdebuf)

ifeq  "$(USE_DLB)" "Y"
DLB = nhdat
else
DLB =
endif

#==========================================
#================ MACROS ==================
#==========================================
# This section creates shorthand macros for many objects
# referenced later on in the Makefile.
#

DEFFILE = $(MSWSYS)/$(GAME).def

#
# Shorten up the location for some files
#

O  = $(OBJ)/

U  = $(UTIL)/

#
# Utility Objects.
#

MAKESRC        = $(U)makedefs.c

SPLEVSRC       = $(U)lev_yacc.c  $(U)lev_$(LEX).c $(U)lev_main.c  $(U)panic.c

DGNCOMPSRC     = $(U)dgn_yacc.c  $(U)dgn_$(LEX).c $(U)dgn_main.c

MAKEOBJS       = $(O)makedefs.o $(O)monst.o $(O)objects.o

SPLEVOBJS      = $(O)lev_yacc.o  $(O)lev_$(LEX).o $(O)lev_main.o \
	$(O)alloc.o   $(O)decl.o      $(O)drawing.o \
	$(O)monst.o   $(O)objects.o   $(O)panic.o

DGNCOMPOBJS    = $(O)dgn_yacc.o  $(O)dgn_$(LEX).o $(O)dgn_main.o \
	$(O)alloc.o   $(O)panic.o

RECOVOBJS      = $(O)recover.o

TILEFILES      = $(WSHR)/monsters.txt $(WSHR)/objects.txt $(WSHR)/other.txt

#
# These are not invoked during a normal game build in 3.4
#
TEXT_IO        = $(O)tiletext.o  $(O)tiletxt.o   $(O)drawing.o \
	$(O)decl.o    $(O)monst.o     $(O)objects.o

TEXT_IO32      = $(O)tilete32.o $(O)tiletx32.o $(O)drawing.o \
	$(O)decl.o    $(O)monst.o     $(O)objects.o

GIFREADERS     = $(O)gifread.o   $(O)alloc.o $(O)panic.o
GIFREADERS32   = $(O)gifrd32.o $(O)alloc.o $(O)panic.o

PPMWRITERS     = $(O)ppmwrite.o $(O)alloc.o $(O)panic.o

#
#  Object files for the game itself.
#

VOBJ01 = $(O)allmain.o  $(O)alloc.o    $(O)apply.o    $(O)artifact.o
VOBJ02 = $(O)attrib.o   $(O)ball.o     $(O)bones.o    $(O)botl.o
VOBJ03 = $(O)cmd.o      $(O)dbridge.o  $(O)decl.o     $(O)detect.o
VOBJ04 = $(O)dig.o      $(O)display.o  $(O)do.o       $(O)do_name.o
VOBJ05 = $(O)do_wear.o  $(O)dog.o      $(O)dogmove.o  $(O)dokick.o
VOBJ06 = $(O)dothrow.o  $(O)drawing.o  $(O)dungeon.o  $(O)eat.o
VOBJ07 = $(O)end.o      $(O)engrave.o  $(O)exper.o    $(O)explode.o
VOBJ08 = $(O)extralev.o $(O)files.o    $(O)fountain.o $(O)hack.o
VOBJ09 = $(O)hacklib.o  $(O)invent.o   $(O)light.o    $(O)lock.o
VOBJ10 = $(O)mail.o     $(O)makemon.o  $(O)mapglyph.o $(O)mcastu.o
VOBJ11 = $(O)mhitm.o    $(O)mhitu.o    $(O)minion.o   $(O)mklev.o
VOBJ12 = $(O)mkmap.o    $(O)mkmaze.o   $(O)mkobj.o    $(O)mkroom.o
VOBJ13 = $(O)mon.o      $(O)mondata.o  $(O)monmove.o  $(O)monst.o
VOBJ14 = $(O)monstr.o   $(O)mplayer.o  $(O)mthrowu.o  $(O)muse.o
VOBJ15 = $(O)music.o    $(O)o_init.o   $(O)objects.o  $(O)objnam.o
VOBJ16 = $(O)options.o  $(O)pager.o    $(O)pickup.o   $(O)pline.o
VOBJ17 = $(O)polyself.o $(O)potion.o   $(O)pray.o     $(O)priest.o
VOBJ18 = $(O)quest.o    $(O)questpgr.o $(RANDOM)      $(O)read.o
VOBJ19 = $(O)rect.o     $(O)region.o   $(O)restore.o  $(O)rip.o
VOBJ20 = $(O)rnd.o      $(O)role.o     $(O)rumors.o   $(O)save.o
VOBJ21 = $(O)shk.o      $(O)shknam.o   $(O)sit.o      $(O)sounds.o
VOBJ22 = $(O)sp_lev.o   $(O)spell.o    $(O)steal.o    $(O)steed.o
VOBJ23 = $(O)sys.o      $(O)teleport.o $(O)timeout.o  $(O)topten.o
VOBJ24 = $(O)track.o    $(O)trap.o     $(O)u_init.o   $(O)uhitm.o
VOBJ25 = $(O)vault.o    $(O)vis_tab.o  $(O)vision.o   $(O)weapon.o
VOBJ26 = $(O)were.o     $(O)wield.o    $(O)windows.o  $(O)wizard.o
VOBJ27 = $(O)worm.o     $(O)worn.o     $(O)write.o    $(O)zap.o

DLBOBJ = $(O)dlb.o

REGEX  = $(O)cppregex.o

TTYOBJ = $(O)topl.o     $(O)getline.o  $(O)wintty.o

SOBJ   = $(O)winnt.o    $(O)pcsys.o      $(O)pcunix.o  \
	$(SOUND) $(O)pcmain.o $(O)nhlan.o

OBJS   = $(VOBJ01) $(VOBJ02) $(VOBJ03) $(VOBJ04) $(VOBJ05) \
	$(VOBJ06) $(VOBJ07) $(VOBJ08) $(VOBJ09) $(VOBJ10) \
	$(VOBJ11) $(VOBJ12) $(VOBJ13) $(VOBJ14) $(VOBJ15) \
	$(VOBJ16) $(VOBJ17) $(VOBJ18) $(VOBJ19) $(VOBJ20) \
	$(VOBJ21) $(VOBJ22) $(VOBJ23) $(VOBJ24) $(VOBJ25) \
	$(VOBJ26) $(VOBJ27) $(REGEX)

GUIOBJ  = $(O)mhaskyn.o $(O)mhdlg.o \
	$(O)mhfont.o $(O)mhinput.o $(O)mhmain.o $(O)mhmap.o \
	$(O)mhmenu.o $(O)mhmsgwnd.o $(O)mhrip.o $(O)mhsplash.o \
	$(O)mhstatus.o $(O)mhtext.o $(O)mswproc.o $(O)winhack.o

GUIHDR = $(MSWIN)/mhaskyn.h $(MSWIN)/mhdlg.h $(MSWIN)/mhfont.h \
	$(MSWIN)/mhinput.h $(MSWIN)/mhmain.h $(MSWIN)/mhmap.h \
	$(MSWIN)/mhmenu.h $(MSWIN)/mhmsg.h $(MSWIN)/mhmsgwnd.h \
	$(MSWIN)/mhrip.h $(MSWIN)/mhstatus.h \
	$(MSWIN)/mhtext.h $(MSWIN)/resource.h $(MSWIN)/winMS.h

KEYDLLS = $(GAMEDIR)/nhdefkey.dll $(GAMEDIR)/nh340key.dll $(GAMEDIR)/nhraykey.dll

TILEUTIL16  = $(UTIL)/tile2bmp.exe
TILEBMP16   = $(SRC)/tiles.bmp

TILEUTIL32  = $(UTIL)/til2bm32.exe
TILEBMP32   = $(SRC)/tiles32.bmp

SOUND = $(OBJ)/ntsound.o
#SOUND =

VVOBJ = $(O)version.o

ALLOBJ = $(SOBJ) $(DLBOBJ) $(WOBJ) $(OBJS) $(VVOBJ)

OPTIONS_FILE = $(DAT)\options

#==========================================
# Header file macros
#==========================================

CONFIG_H = $(INCL)/config.h $(INCL)/config1.h $(INCL)/tradstdc.h \
	       $(INCL)/global.h $(INCL)/coord.h $(INCL)/vmsconf.h \
	       $(INCL)/system.h $(INCL)/unixconf.h $(INCL)/os2conf.h \
	       $(INCL)/micro.h $(INCL)/pcconf.h $(INCL)/tosconf.h \
	       $(INCL)/amiconf.h $(INCL)/macconf.h $(INCL)/beconf.h \
	       $(INCL)/ntconf.h

HACK_H = $(INCL)/hack.h $(CONFIG_H) $(INCL)/align.h $(INCL)/context.h \
	       $(INCL)/dungeon.h $(INCL)/monsym.h $(INCL)/mkroom.h \
	       $(INCL)/objclass.h $(INCL)/youprop.h $(INCL)/prop.h \
	       $(INCL)/permonst.h $(INCL)/monattk.h \
	       $(INCL)/monflag.h $(INCL)/mondata.h $(INCL)/pm.h \
	       $(INCL)/wintype.h $(INCL)/decl.h $(INCL)/quest.h \
	       $(INCL)/spell.h $(INCL)/color.h $(INCL)/obj.h \
	       $(INCL)/you.h $(INCL)/attrib.h $(INCL)/monst.h $(INCL)/lint.h \
	       $(INCL)/mextra.h $(INCL)/skills.h $(INCL)/onames.h \
	       $(INCL)/timeout.h $(INCL)/trap.h $(INCL)/flag.h $(INCL)/rm.h \
	       $(INCL)/vision.h $(INCL)/display.h $(INCL)/engrave.h \
	       $(INCL)/rect.h $(INCL)/region.h $(INCL)/winprocs.h \
	       $(INCL)/wintty.h $(INCL)/sys.h $(INCL)/trampoli.h

LEV_H       = $(INCL)/lev.h
DGN_FILE_H  = $(INCL)/dgn_file.h
LEV_COMP_H  = $(INCL)/lev_comp.h
SP_LEV_H    = $(INCL)/sp_lev.h
TILE_H      = ../win/share/tile.h

#==========================================
# Miscellaneous
#==========================================

DATABASE = $(DAT)/data.base

#==========================================
#================ RULES ==================
#==========================================

.SUFFIXES: .exe .o .til .uu .c .y .l

#==========================================
# Rules for files in src
#==========================================

$(OBJ)/%.o : /%.c
	$(cc) $(CFLAGS)  -o$@ $<

$(OBJ)/%.o : $(SRC)/%.c
	$(cc) $(CFLAGS)   -o$@  $<

#==========================================
# Rules for files in sys/share
#==========================================

$(OBJ)/%.o : $(SSYS)/%.c
	$(cc) $(CFLAGS)  -o$@  $<

$(OBJ)/%.o : $(SSYS)/%.cpp
	g++ $(CFLAGS) -std=c++11  -o$@  $<

#==========================================
# Rules for files in sys/winnt
#==========================================

$(OBJ)/%.o : $(MSWSYS)/%.c
	$(cc) $(CFLAGS)  -o$@  $<

$(INCL)/%.h : $(MSWSYS)/%.h
	@copy $< $@

#==========================================
# Rules for files in util
#==========================================

$(OBJ)/%.o : $(UTIL)/%.c
	$(cc) $(CFLAGSU) -o$@ $<

#==========================================
# Rules for files in win/share
#==========================================

$(OBJ)/%.o : $(WSHR)/%.c
	$(cc) $(CFLAGS)  -o$@ $<

$(INCL)/%.h : $(WSHR)/%.h
	@copy $< $@

#{$(WSHR)}.txt{$(DAT)}.txt:
#	@copy $< $@

#==========================================
# Rules for files in win/tty
#==========================================

$(OBJ)/%.o : $(TTY)/%.c
	$(cc) $(CFLAGS)  -o$@  $<

#==========================================
# Rules for files in win/win32
#==========================================

$(OBJ)/%.o : $(MSWIN)/%.c
	$(cc) $(CFLAGS)  -o$@  $<

#==========================================
#=============== TARGETS ==================
#==========================================

# Since DOS doesn't allow / as path separator, and GCC doesn't allow \ as
# path separator, we must change all pathnames when performing DOS commands.
# This is done by blindly applying $(subst /,\, ...) on every command.
# Where any command contain / for another reason (switch char, or echoing
# comment lines to lev/dungeon files) a little more care is taken.

#
#  The default make target (so just typing 'nmake' is useful).
#
default : install

#
#  Everything
#

all :   install

install: graphicschk $(O)obj.tag $(GAMEDIR)/NetHack.exe $(GAMEDIR)/NetHackW.exe $(O)install.tag
	@echo NetHack is up to date.
	@echo Done.


$(O)install.tag:  $(DAT)/data    $(DAT)/rumors    $(DAT)/dungeon \
	       $(DAT)/oracles $(DAT)/quest.dat $(O)sp_lev.tag $(DLB)
ifeq  "$(USE_DLB)" "Y"
	$(subst /,\,copy nhdat                $(GAMEDIR))
	$(subst /,\,copy $(DAT)/license       $(GAMEDIR))
	$(subst /,\,copy $(DAT)/opthelp       $(GAMEDIR))
else
	$(subst /,\,copy $(DAT)/*.            $(GAMEDIR))
	$(subst /,\,copy $(DAT)/*.dat         $(GAMEDIR))
	$(subst /,\,copy $(DAT)/*.lev         $(GAMEDIR))
	$(subst /,\,if exist $(GAMEDIR)/makefile del $(GAMEDIR)/makefile)
endif
	$(subst /,\,if not exist $(GAMEDIR)/sysconf copy $(MSWSYS)/sysconf $(GAMEDIR))
	$(subst /,\,if exist $(DAT)/symbols copy $(DAT)/symbols $(GAMEDIR))
	$(subst /,\,if exist $(DOC)/guidebook.txt copy $(DOC)/guidebook.txt $(GAMEDIR)/Guidebook.txt)
	$(subst /,\,if exist $(DOC)/nethack.txt copy $(DOC)/nethack.txt $(GAMEDIR)/NetHack.txt)
	$(subst /,\,copy $(MSWSYS)/defaults.nh   $(GAMEDIR)/defaults.nh)
	$(subst /,\,echo install done > $@)

#  copy $(MSWSYS)/winnt.hlp    $(GAMEDIR)

recover: $(U)recover.exe
	$(subst /,\,if exist $(U)recover.exe copy $(U)recover.exe  $(GAMEDIR))
	$(subst /,\,if exist $(DOC)/recover.txt copy $(DOC)/recover.txt $(GAMEDIR)/recover.txt)

$(O)sp_lev.tag: $(O)utility.tag $(DAT)/bigroom.des  $(DAT)/castle.des \
	 $(DAT)/endgame.des $(DAT)/gehennom.des $(DAT)/knox.des   \
	 $(DAT)/medusa.des  $(DAT)/oracle.des   $(DAT)/tower.des  \
	 $(DAT)/yendor.des  $(DAT)/arch.des     $(DAT)/barb.des   \
	 $(DAT)/caveman.des $(DAT)/healer.des   $(DAT)/knight.des \
	 $(DAT)/monk.des    $(DAT)/priest.des   $(DAT)/ranger.des \
	 $(DAT)/rogue.des   $(DAT)/samurai.des  $(DAT)/sokoban.des \
	 $(DAT)/tourist.des $(DAT)/valkyrie.des $(DAT)/wizard.des
	$(subst /,\,$(U)levcomp $(DAT)/bigroom.des)
	$(subst /,\,$(U)levcomp $(DAT)/castle.des)
	$(subst /,\,$(U)levcomp $(DAT)/endgame.des)
	$(subst /,\,$(U)levcomp $(DAT)/gehennom.des)
	$(subst /,\,$(U)levcomp $(DAT)/knox.des)
	$(subst /,\,$(U)levcomp $(DAT)/mines.des)
	$(subst /,\,$(U)levcomp $(DAT)/medusa.des)
	$(subst /,\,$(U)levcomp $(DAT)/oracle.des)
	$(subst /,\,$(U)levcomp $(DAT)/sokoban.des)
	$(subst /,\,$(U)levcomp $(DAT)/tower.des)
	$(subst /,\,$(U)levcomp $(DAT)/yendor.des)
	$(subst /,\,$(U)levcomp $(DAT)/arch.des)
	$(subst /,\,$(U)levcomp $(DAT)/barb.des)
	$(subst /,\,$(U)levcomp $(DAT)/caveman.des)
	$(subst /,\,$(U)levcomp $(DAT)/healer.des)
	$(subst /,\,$(U)levcomp $(DAT)/knight.des)
	$(subst /,\,$(U)levcomp $(DAT)/monk.des)
	$(subst /,\,$(U)levcomp $(DAT)/priest.des)
	$(subst /,\,$(U)levcomp $(DAT)/ranger.des)
	$(subst /,\,$(U)levcomp $(DAT)/rogue.des)
	$(subst /,\,$(U)levcomp $(DAT)/samurai.des)
	$(subst /,\,$(U)levcomp $(DAT)/tourist.des)
	$(subst /,\,$(U)levcomp $(DAT)/valkyrie.des)
	$(subst /,\,$(U)levcomp $(DAT)/wizard.des)
	$(subst /,\,copy *.lev $(DAT))
	$(subst /,\,del *.lev)
	$(subst /,\,echo sp_levs done > $(O)sp_lev.tag)

$(O)utility.tag: $(INCL)/date.h $(INCL)/onames.h $(INCL)/pm.h \
	 $(SRC)/monstr.c $(SRC)/vis_tab.c $(U)levcomp.exe $(INCL)/vis_tab.h \
	 $(U)dgncomp.exe $(TILEUTIL16)
	$(subst /,\,@echo utilities made >$@)
	@echo utilities made.

tileutil: $(U)gif2txt.exe $(U)gif2tx32.exe $(U)txt2ppm.exe
	@echo Optional tile development utilities are up to date.

$(O)winres.o: $(TILEBMP16) $(MSWIN)/winhack.rc $(MSWIN)/mnsel.bmp \
	 $(MSWIN)/mnselcnt.bmp $(MSWIN)/mnunsel.bmp \
	 $(MSWIN)/petmark.bmp $(MSWIN)/pilemark.bmp $(MSWIN)/NetHack.ico $(MSWIN)/rip.bmp \
	 $(MSWIN)/splash.bmp
	@$(rc) -o$@ --include-dir $(MSWIN) -i $(MSWIN)/winhack.rc

$(O)conres.o: $(MSWSYS)/console.rc $(MSWSYS)/NetHack.ico 
	@$(rc) -o$@ --include-dir $(MSWSYS) -i $(MSWSYS)/console.rc

#==========================================
#  The game targets.
#==========================================
$(O)gamedir.tag:
	$(subst /,\,@if not exist $(GAMEDIR)/*.* echo creating directory $(GAMEDIR))
	$(subst /,\,@if not exist $(GAMEDIR)/*.* mkdir $(GAMEDIR))
	$(subst /,\,@echo directory created > $@)

$(GAMEDIR)/NetHack.exe : $(O)gamedir.tag $(O)tile.o $(O)nttty.o $(O)guistub.o \
			$(ALLOBJ) $(TTYOBJ) $(GUIOBJ) $(O)conres.o $(KEYDLLS)
	@echo Linking $@...
	$(link) $(lflags) -o$@ $(ALLOBJ) $(TTYOBJ) $(O)nttty.o $(O)tile.o \
		$(O)guistub.o $(O)conres.o $(conlibs) -static -lstdc++
	$(subst /,\,@if exist $(O)install.tag del $(O)install.tag)

$(GAMEDIR)/NetHackW.exe : $(O)gamedir.tag $(O)tile.o $(O)ttystub.o \
			$(ALLOBJ) $(TTYOBJ) $(GUIOBJ) $(O)winres.o $(KEYDLLS)
	@echo Linking $@...
	$(link) $(lflags) -mwindows -o$@ $(ALLOBJ) $(GUIOBJ) $(O)tile.o $(O)ttystub.o \
		$(O)winres.o $(guilibs) -static -lstdc++
	$(subst /,\,@if exist $(O)install.tag del $(O)install.tag)

$(O)nhdefkey.o:
	$(cc) $(CFLAGS) -DBUILD_DLL -o$@ $(MSWSYS)/nhdefkey.c 

$(GAMEDIR)/nhdefkey.dll : $(O)nhdefkey.o $(O)gamedir.tag
	@echo Linking $@
	$(cc) -shared -Wl,--export-all-symbols \
		-Wl,--add-stdcall-alias -o $@ $<

$(O)nh340key.o:
	$(cc) $(CFLAGS) -DBUILD_DLL -o$@ $(MSWSYS)/nh340key.c 

$(GAMEDIR)/nh340key.dll : $(O)nh340key.o $(O)gamedir.tag
	@echo Linking $@
	$(cc) -shared -Wl,--export-all-symbols \
		-Wl,--add-stdcall-alias -o $@ $<

$(O)nhraykey.o:
		$(cc) $(CFLAGS) -DBUILD_DLL -o$@ $(MSWSYS)/nhraykey.c 

$(GAMEDIR)/nhraykey.dll : $(O)nhraykey.o $(O)gamedir.tag
	@echo Linking $@
	$(cc) -shared -Wl,--export-all-symbols \
		-Wl,--add-stdcall-alias -o $@ $<

$(GAME)_.ico : $(MSWSYS)/$(GAME).ico
	$(subst /,\,@copy $(MSWSYS)/$(GAME).ico $@)

#==========================================
# Create directory for holding object files
#==========================================

graphicschk:
	@echo ----
	@echo NOTE: This build will include tile support.
	@echo ----
	$(subst /,\,@echo graphicschk > graphicschk)

#
#  Secondary Targets.
#

#==========================================
# Makedefs Stuff
#==========================================

$(U)makedefs.exe: $(MAKEOBJS)
	@$(link) $(LFLAGSU) -o$@ $(MAKEOBJS)

$(O)makedefs.o: $(CONFIG_H) $(INCL)/monattk.h $(INCL)/monflag.h \
	 $(INCL)/objclass.h $(INCL)/monsym.h $(INCL)/qtext.h \
	 $(INCL)/patchlevel.h $(U)makedefs.c $(O)obj.tag
	$(cc) $(CFLAGSU) -o$@ $(U)makedefs.c

#
#  date.h should be remade every time any of the source or include
#  files is modified.
#

$(INCL)/date.h $(OPTIONS_FILE): $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -v)

$(INCL)/onames.h : $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -o)

$(INCL)/pm.h : $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -p)

#$(INCL)/trap.h : $(U)makedefs.exe
#  $(U)makedefs -t

$(SRC)/monstr.c: $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -m)

$(INCL)/vis_tab.h: $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -z)

$(SRC)/vis_tab.c: $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -z)

$(DAT)/engrave: $(DAT)/engrave.txt $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -s)

$(DAT)/epitaph: $(DAT)/epitaph.txt $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -s)

$(DAT)/bogusmon: $(DAT)/bogusmon.txt $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -s)



#==========================================
# uudecode utility and uuencoded targets
#==========================================

$(U)uudecode.exe: $(O)uudecode.o
	@$(link) $(LFLAGSU) -o$@ $(O)uudecode.o

$(O)uudecode.o: $(SSYS)/uudecode.c

$(MSWSYS)/NetHack.ico : $(U)uudecode.exe $(MSWSYS)/nhico.uu
	$(subst /,\,$(U)uudecode.exe $(MSWSYS)/nhico.uu)
	$(subst /,\,copy NetHack.ico $@)
	del NetHack.ico

$(MSWIN)/NetHack.ico : $(MSWSYS)/NetHack.ico
	$(subst /,\,copy $< $@)

$(MSWIN)/mnsel.bmp: $(U)uudecode.exe $(MSWIN)/mnsel.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/mnsel.uu)
	$(subst /,\,copy mnsel.bmp $@)
	del mnsel.bmp

$(MSWIN)/mnselcnt.bmp: $(U)uudecode.exe $(MSWIN)/mnselcnt.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/mnselcnt.uu)
	$(subst /,\,copy mnselcnt.bmp $@)
	del mnselcnt.bmp

$(MSWIN)/mnunsel.bmp: $(U)uudecode.exe $(MSWIN)/mnunsel.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/mnunsel.uu)
	$(subst /,\,copy mnunsel.bmp $@)
	del mnunsel.bmp

$(MSWIN)/petmark.bmp: $(U)uudecode.exe $(MSWIN)/petmark.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/petmark.uu)
	$(subst /,\,copy petmark.bmp $@)
	del petmark.bmp

$(MSWIN)/pilemark.bmp: $(U)uudecode.exe $(MSWIN)/pilemark.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/pilemark.uu)
	$(subst /,\,copy pilemark.bmp $@)
	del pilemark.bmp

$(MSWIN)/rip.bmp: $(U)uudecode.exe $(MSWIN)/rip.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/rip.uu)
	$(subst /,\,copy rip.bmp $@)
	del rip.bmp

$(MSWIN)/splash.bmp: $(U)uudecode.exe $(MSWIN)/splash.uu
	$(subst /,\,$(U)uudecode.exe $(MSWIN)/splash.uu)
	$(subst /,\,copy splash.bmp $@)
	del splash.bmp


#==========================================
# Level Compiler Stuff
#==========================================

LEVCFLAGS=$(cflags) -c -DWIN32 -D_WIN32 -I../include $(cdebug) -DDLB

$(U)levcomp.exe: $(SPLEVOBJS)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(SPLEVOBJS)

$(O)lev_yacc.o: $(HACK_H)   $(SP_LEV_H) $(INCL)/lev_comp.h $(U)lev_yacc.c
	$(cc) $(LEVCFLAGS) -o$@ $(U)lev_yacc.c

$(O)lev_$(LEX).o: $(HACK_H)   $(INCL)/lev_comp.h $(SP_LEV_H) \
	$(U)lev_$(LEX).c
	$(cc) $(LEVCFLAGS) -o$@ $(U)lev_$(LEX).c

$(O)lev_main.o:   $(U)lev_main.c $(HACK_H)   $(SP_LEV_H)
	$(cc) $(LEVCFLAGS) -o$@ $(U)lev_main.c


$(U)lev_yacc.c $(INCL)/lev_comp.h : $(U)lev_comp.y
ifeq  "$(DO_YACC)" "YACC_ACT"
	$(subst /,\,$(YACC) -d $(U)lev_comp.y)
	$(subst /,\,copy $(YTABC) $(U)lev_yacc.c)
	$(subst /,\,copy $(YTABH) $(INCL)/lev_comp.h)
	$(subst /,\,@del $(YTABC))
	$(subst /,\,@del $(YTABH))

else
	@echo $(U)lev_comp.y has changed.
	@echo To update $(U)lev_yacc.c and $(INCL)/lev_comp.h run $(YACC).
	@echo ---
	@echo For now, we will copy the prebuilt lev_yacc.c and
	@echo lev_comp.h from $(SSYS) into $(UTIL) and use them.
	$(subst /,\,@copy $(SSYS)/lev_yacc.c $(U)lev_yacc.c >nul)
	$(subst /,\,@copy $(SSYS)/lev_comp.h $(INCL)/lev_comp.h >nul)
	$(subst /,\,echo.>>$(U)lev_yacc.c)
	$(subst /,\,echo.>>$(INCL)/lev_comp.h)
endif

$(U)lev_$(LEX).c: $(U)lev_comp.l
ifeq  "$(DO_LEX)" "LEX_ACT"
	$(subst /,\,$(LEX) $(FLEXSKEL) $(U)lev_comp.l)
	$(subst /,\,copy $(LEXYYC) $@)
	$(subst /,\,@del $(LEXYYC))
else
	@echo $(U)lev_comp.l has changed. To update $@ run $(LEX).
	@echo ---
	@echo For now, we will copy the prebuilt lev_lex.c
	@echo from $(SSYS) into $(UTIL) and use it.
	$(subst /,\,@copy $(SSYS)/lev_lex.c $@ >nul)
	$(subst /,\,echo.>>$@)
endif

#==========================================
# Dungeon Compiler Stuff
#==========================================

$(U)dgncomp.exe: $(DGNCOMPOBJS)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(DGNCOMPOBJS)


$(O)dgn_yacc.o:   $(HACK_H)   $(DGN_FILE_H) $(INCL)/dgn_comp.h $(U)dgn_yacc.c
	$(cc) $(LEVCFLAGS) -o$@ $(U)dgn_yacc.c

$(O)dgn_$(LEX).o: $(HACK_H)   $(DGN_FILE_H)  $(INCL)/dgn_comp.h \
	 $(U)dgn_$(LEX).c
	$(cc) $(LEVCFLAGS) -o$@ $(U)dgn_$(LEX).c

$(O)dgn_main.o:   $(HACK_H) $(U)dgn_main.c
	$(cc) $(LEVCFLAGS) -o$@ $(U)dgn_main.c

$(U)dgn_yacc.c $(INCL)/dgn_comp.h : $(U)dgn_comp.y
ifeq  "$(DO_YACC)" "YACC_ACT"
	$(subst /,\,$(YACC) -d $(U)dgn_comp.y)
	$(subst /,\,copy $(YTABC) $(U)dgn_yacc.c)
	$(subst /,\,copy $(YTABH) $(INCL)/dgn_comp.h)
	$(subst /,\,@del $(YTABC))
	$(subst /,\,@del $(YTABH))
else
	@echo $(U)dgn_comp.y has changed. To update dgn_yacc.c and
	@echo $(INCL)/dgn_comp.h run $(YACC).
	@echo ---
	@echo For now, we will copy the prebuilt $(U)dgn_yacc.c and
	@echo dgn_comp.h from $(SSYS) into $(UTIL) and use them.
	$(subst /,\,@copy $(SSYS)/dgn_yacc.c $(U)dgn_yacc.c >nul)
	$(subst /,\,@copy $(SSYS)/dgn_comp.h $(INCL)/dgn_comp.h >nul)
	$(subst /,\,echo.>>$(U)dgn_yacc.c)
	$(subst /,\,echo.>>$(INCL)/dgn_comp.h)
endif

$(U)dgn_$(LEX).c: $(U)dgn_comp.l
ifeq  "$(DO_LEX)" "LEX_ACT"
	$(subst /,\,$(LEX) $(FLEXSKEL) $(U)dgn_comp.l)
	$(subst /,\,copy $(LEXYYC) $@)
	$(subst /,\,@del $(LEXYYC))
else
	@echo $(U)dgn_comp.l has changed. To update $@ run $(LEX).
	@echo ---
	@echo For now, we will copy the prebuilt dgn_lex.c
	@echo from $(SSYS) into $(UTIL) and use it.
	$(subst /,\,@copy $(SSYS)/dgn_lex.c $@ >nul)
	$(subst /,\,echo.>>$@)
endif

#==========================================
# Create directory for holding object files
#==========================================

$(O)obj.tag:
	$(subst /,\,@if not exist $(OBJ)/*.* echo creating directory $(OBJ))
	$(subst /,\,@if not exist $(OBJ)/*.* mkdir $(OBJ))
	$(subst /,\,@echo directory created > $@)


#==========================================
#=========== SECONDARY TARGETS ============
#==========================================

#===========================================
# Header files NOT distributed in ../include
#===========================================

$(INCL)/win32api.h: $(MSWSYS)/win32api.h
	$(subst /,\,copy $(MSWSYS)/win32api.h $@)


#==========================================
# DLB utility and nhdat file creation
#==========================================

$(U)dlb_main.exe: $(DLBOBJ) $(O)dlb.o
	@$(link) $(LFLAGSU) -o$@ $(O)dlb_main.o $(O)dlb.o $(O)alloc.o $(O)panic.o


$(O)dlb.o:   $(O)dlb_main.o $(O)alloc.o $(O)panic.o $(INCL)/dlb.h
	$(cc) $(CFLAGS) -o$@ $(SRC)/dlb.c

$(O)dlb_main.o: $(UTIL)/dlb_main.c $(INCL)/config.h $(INCL)/dlb.h
	$(cc) $(CFLAGS) -o$@ $(UTIL)/dlb_main.c

$(DAT)/porthelp: $(MSWSYS)/porthelp
	$(subst /,\,@copy $(MSWSYS)/porthelp $@ >nul)

nhdat:  $(U)dlb_main.exe $(DAT)/data $(DAT)/oracles $(OPTIONS_FILE) \
	 $(DAT)/quest.dat $(DAT)/rumors $(DAT)/help $(DAT)/hh $(DAT)/cmdhelp \
	 $(DAT)/history $(DAT)/opthelp $(DAT)/wizhelp $(DAT)/dungeon \
	 $(DAT)/porthelp $(DAT)/license $(DAT)/engrave $(DAT)/epitaph $(DAT)/bogusmon $(DAT)/tribute $(O)sp_lev.tag
	$(subst /,\,echo data >$(DAT)/dlb.lst)
	$(subst /,\,echo oracles >>$(DAT)/dlb.lst)
	$(subst /,\,if exist $(DAT)/options echo options >>$(DAT)/dlb.lst)
	$(subst /,\,if exist $(DAT)/ttyoptions echo ttyoptions >>$(DAT)/dlb.lst)
	$(subst /,\,if exist $(DAT)/guioptions echo guioptions >>$(DAT)/dlb.lst)
	$(subst /,\,if exist $(DAT)/porthelp echo porthelp >>$(DAT)/dlb.lst)
	$(subst /,\,echo quest.dat >>$(DAT)/dlb.lst)
	$(subst /,\,echo rumors >>$(DAT)/dlb.lst)
	$(subst /,\,echo help >>$(DAT)/dlb.lst)
	$(subst /,\,echo hh >>$(DAT)/dlb.lst)
	$(subst /,\,echo cmdhelp >>$(DAT)/dlb.lst)
	$(subst /,\,echo history >>$(DAT)/dlb.lst)
	$(subst /,\,echo opthelp >>$(DAT)/dlb.lst)
	$(subst /,\,echo wizhelp >>$(DAT)/dlb.lst)
	$(subst /,\,echo dungeon >>$(DAT)/dlb.lst)
	$(subst /,\,echo license >>$(DAT)/dlb.lst)
	$(subst /,\,echo engrave >>$(DAT)/dlb.lst)
	$(subst /,\,echo epitaph >>$(DAT)/dlb.lst)
	$(subst /,\,echo bogusmon >>$(DAT)/dlb.lst)
	$(subst /,\,echo tribute >>$(DAT)/dlb.lst)
	dir /l /b /-p $(subst /,\,$(DAT)/*.lev >>$(DAT)/dlb.lst)
	$(subst /,\,$(U)dlb_main CcIf $(DAT) dlb.lst $(SRC)/nhdat)

#==========================================
#  Recover Utility
#==========================================

$(U)recover.exe: $(RECOVOBJS)
	$(link) $(LFLAGSU) -o$@ $(RECOVOBJS)

$(O)recover.o: $(CONFIG_H) $(U)recover.c $(INCL)/win32api.h
	$(cc) $(CFLAGSU) -o$@ $(U)recover.c

#==========================================
#  Tile Mapping
#==========================================

$(SRC)/tile.c: $(U)tilemap.exe
	@echo A new $@ has been created
	@$(U)tilemap

$(U)tilemap.exe: $(O)tilemap.o
	@$(link) $(LFLAGSU) -o$@ $(O)tilemap.o

$(O)tilemap.o: $(WSHR)/tilemap.c $(HACK_H)
	$(cc) $(CFLAGSU) -o$@ $(WSHR)/tilemap.c

$(O)tiletx32.o: $(WSHR)/tilemap.c $(HACK_H)
	$(cc) $(CFLAGS) -DTILETEXT -DTILE_X=32 -DTILE_Y=32 -o$@ $(WSHR)/tilemap.c

$(O)tiletxt.o: $(WSHR)/tilemap.c $(HACK_H)
	$(cc) $(CFLAGS) -DTILETEXT -o$@ $(WSHR)/tilemap.c

$(O)gifread.o: $(WSHR)/gifread.c  $(CONFIG_H) $(TILE_H)
	$(cc) $(CFLAGS) -I$(WSHR) -o$@ $(WSHR)/gifread.c

$(O)gifrd32.o: $(WSHR)/gifread.c  $(CONFIG_H) $(TILE_H)
	$(cc) $(CFLAGS) -I$(WSHR) -DTILE_X=32 -DTILE_Y=32 -o$@ $(WSHR)/gifread.c

$(O)ppmwrite.o: $(WSHR)/ppmwrite.c $(CONFIG_H) $(TILE_H)
	$(cc) $(CFLAGS) -I$(WSHR) -o$@ $(WSHR)/ppmwrite.c

$(O)tiletext.o: $(WSHR)/tiletext.c  $(CONFIG_H) $(TILE_H)
	$(cc) $(CFLAGS) -I$(WSHR) -o$@ $(WSHR)/tiletext.c

$(O)tilete32.o: $(WSHR)/tiletext.c  $(CONFIG_H) $(TILE_H)
	$(cc) $(CFLAGS) -I$(WSHR) -DTILE_X=32 -DTILE_Y=32 -o$@ $(WSHR)/tiletext.c

#==========================================
# Optional Tile Utilities
#==========================================

$(U)gif2txt.exe: $(GIFREADERS) $(TEXT_IO)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(GIFREADERS) $(TEXT_IO)

$(U)gif2tx32.exe: $(GIFREADERS32) $(TEXT_IO32)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(GIFREADERS32) $(TEXT_IO32)


$(U)txt2ppm.exe: $(PPMWRITERS) $(TEXT_IO)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(PPMWRITERS) $(TEXT_IO)


$(TILEBMP16): $(TILEUTIL16) $(TILEFILES)
	@echo Creating 16x16 binary tile files (this may take some time)
	$(subst /,\,@$(U)tile2bmp $(TILEBMP16))

#$(TILEBMP32): $(TILEUTIL32) $(TILEFILES32)
#	@echo Creating 32x32 binary tile files (this may take some time)
#	$(subst /,\,@$(U)til2bm32 $(TILEBMP32))

$(U)tile2bmp.exe: $(O)tile2bmp.o $(TEXT_IO)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(O)tile2bmp.o $(TEXT_IO)

$(U)til2bm32.exe: $(O)til2bm32.o $(TEXT_IO32)
	@echo Linking $@...
	@$(link) $(LFLAGSU) -o$@ $(O)til2bm32.o $(TEXT_IO32)

$(O)tile2bmp.o: $(WSHR)/tile2bmp.c $(HACK_H) $(TILE_H) $(INCL)/win32api.h
	$(cc) $(CFLAGS) -mno-ms-bitfields -I$(WSHR) -o$@ $(WSHR)/tile2bmp.c

$(O)til2bm32.o: $(WSHR)/til2bm32.c $(HACK_H) $(TILE_H) $(INCL)/win32api.h
	$(cc) $(CFLAGS) -I$(WSHR) -DTILE_X=32 -DTILE_Y=32 -o$@ $(WSHR)/til2bm32.c

#==========================================
# Housekeeping
#==========================================

spotless: clean
	$(subst /,\,if exist graphicschk       del graphicschk)
	$(subst /,\,if exist $(INCL)/date.h    del $(INCL)/date.h)
	$(subst /,\,if exist $(INCL)/onames.h  del $(INCL)/onames.h)
	$(subst /,\,if exist $(INCL)/pm.h      del $(INCL)/pm.h)
	$(subst /,\,if exist $(INCL)/vis_tab.h del $(INCL)/vis_tab.h)
	$(subst /,\,if exist $(SRC)/vis_tab.c  del $(SRC)/vis_tab.c)
	$(subst /,\,if exist $(SRC)/tile.c     del $(SRC)/tile.c)
	$(subst /,\,if exist $(U)*.lnk         del $(U)*.lnk)
	$(subst /,\,if exist $(U)*.map         del $(U)*.map)
	$(subst /,\,if exist $(DAT)/data       del $(DAT)/data)
	$(subst /,\,if exist $(DAT)/rumors     del $(DAT)/rumors)
	$(subst /,\,if exist $(DAT)/???-fil?.lev      del $(DAT)/???-fil?.lev)
	$(subst /,\,if exist $(DAT)/???-goal.lev      del $(DAT)/???-goal.lev)
	$(subst /,\,if exist $(DAT)/???-loca.lev      del $(DAT)/???-loca.lev)
	$(subst /,\,if exist $(DAT)/???-strt.lev      del $(DAT)/???-strt.lev)
	$(subst /,\,if exist $(DAT)/air.lev      del $(DAT)/air.lev)
	$(subst /,\,if exist $(DAT)/asmodeus.lev      del $(DAT)/asmodeus.lev)
	$(subst /,\,if exist $(DAT)/astral.lev   del $(DAT)/astral.lev)
	$(subst /,\,if exist $(DAT)/baalz.lev    del $(DAT)/baalz.lev)
	$(subst /,\,if exist $(DAT)/bigrm-*.lev  del $(DAT)/bigrm-*.lev)
	$(subst /,\,if exist $(DAT)/castle.lev   del $(DAT)/castle.lev)
	$(subst /,\,if exist $(DAT)/data    del $(DAT)/data)
	$(subst /,\,if exist $(DAT)/dungeon      del $(DAT)/dungeon)
	$(subst /,\,if exist $(DAT)/dungeon.pdf  del $(DAT)/dungeon.pdf)
	$(subst /,\,if exist $(DAT)/earth.lev    del $(DAT)/earth.lev)
	$(subst /,\,if exist $(DAT)/fakewiz?.lev      del $(DAT)/fakewiz?.lev)
	$(subst /,\,if exist $(DAT)/fire.lev     del $(DAT)/fire.lev)
	$(subst /,\,if exist $(DAT)/juiblex.lev  del $(DAT)/juiblex.lev)
	$(subst /,\,if exist $(DAT)/knox.lev     del $(DAT)/knox.lev)
	$(subst /,\,if exist $(DAT)/medusa-?.lev      del $(DAT)/medusa-?.lev)
	$(subst /,\,if exist $(DAT)/mine*.lev    del $(DAT)/mine*.lev)
	$(subst /,\,if exist $(DAT)/options      del $(DAT)/options)
	$(subst /,\,if exist $(DAT)/ttyoptions   del $(DAT)/ttyoptions)
	$(subst /,\,if exist $(DAT)/guioptions   del $(DAT)/guioptions)
	$(subst /,\,if exist $(DAT)/oracle.lev   del $(DAT)/oracle.lev)
	$(subst /,\,if exist $(DAT)/oracles      del $(DAT)/oracles)
	$(subst /,\,if exist $(DAT)/orcus.lev    del $(DAT)/orcus.lev)
	$(subst /,\,if exist $(DAT)/rumors  del $(DAT)/rumors)
	$(subst /,\,if exist $(DAT)/quest.dat    del $(DAT)/quest.dat)
	$(subst /,\,if exist $(DAT)/sanctum.lev  del $(DAT)/sanctum.lev)
	$(subst /,\,if exist $(DAT)/soko?-?.lev  del $(DAT)/soko?-?.lev)
	$(subst /,\,if exist $(DAT)/tower?.lev   del $(DAT)/tower?.lev)
	$(subst /,\,if exist $(DAT)/valley.lev   del $(DAT)/valley.lev)
	$(subst /,\,if exist $(DAT)/water.lev    del $(DAT)/water.lev)
	$(subst /,\,if exist $(DAT)/wizard?.lev  del $(DAT)/wizard?.lev)
	$(subst /,\,if exist $(O)sp_lev.tag     del $(O)sp_lev.tag)
	$(subst /,\,if exist $(SRC)/monstr.c    del $(SRC)/monstr.c)
	$(subst /,\,if exist $(SRC)/vis_tab.c   del $(SRC)/vis_tab.c)
	$(subst /,\,if exist $(U)recover.exe    del $(U)recover.exe)
	$(subst /,\,if exist $(DAT)/dlb.lst      del $(DAT)/dlb.lst)
	$(subst /,\,if exist nhdat.         del nhdat.)
ifneq "$(OBJ)" ""
	$(subst /,\,rmdir $(OBJ)) /s /Q
endif

clean:
	$(subst /,\,if exist $(O)*.o del $(O)*.o)
	$(subst /,\,if exist $(O)utility.tag   del $(O)utility.tag)
	$(subst /,\,if exist $(U)makedefs.exe  del $(U)makedefs.exe)
	$(subst /,\,if exist $(U)levcomp.exe   del $(U)levcomp.exe)
	$(subst /,\,if exist $(U)dgncomp.exe   del $(U)dgncomp.exe)
	$(subst /,\,if exist $(SRC)/*.lnk      del $(SRC)/*.lnk)
	$(subst /,\,if exist $(SRC)/*.map      del $(SRC)/*.map)
	$(subst /,\,if exist $(O)install.tag   del $(O)install.tag)
	$(subst /,\,if exist $(O)gamedir.tag  del $(O)gamedir.tag)
	$(subst /,\,if exist $(O)obj.tag      del $(O)obj.tag)
	$(subst /,\,if exist $(TILEBMP16)        del $(TILEBMP16))
	$(subst /,\,if exist $(TILEBMP32)        del $(TILEBMP32))

#===================================================================
# OTHER DEPENDENCIES
#===================================================================

#
# dat dependencies
#

$(DAT)/data: $(O)utility.tag    $(DATABASE)
	$(subst /,\,$(U)makedefs -d)

$(DAT)/rumors: $(O)utility.tag    $(DAT)/rumors.tru   $(DAT)/rumors.fal
	$(subst /,\,$(U)makedefs -r)

$(DAT)/quest.dat: $(O)utility.tag  $(DAT)/quest.txt
	$(subst /,\,$(U)makedefs -q)

$(DAT)/oracles: $(O)utility.tag    $(DAT)/oracles.txt
	$(subst /,\,$(U)makedefs -h)

$(DAT)/dungeon: $(O)utility.tag  $(DAT)/dungeon.def
	$(subst /,\,$(U)makedefs -e)
	$(subst /,\,$(U)dgncomp $(DAT)/dungeon.pdf)

#
# NT dependencies
#

$(O)nttty.o:   $(HACK_H) $(TILE_H) $(INCL)/win32api.h $(MSWSYS)/nttty.c
	$(cc) $(CFLAGS) -I$(WSHR) -o$@  $(MSWSYS)/nttty.c
$(O)winnt.o: $(HACK_H) $(INCL)/win32api.h $(MSWSYS)/winnt.c
	$(cc) $(CFLAGS) -o$@  $(MSWSYS)/winnt.c
$(O)ntsound.o: $(HACK_H) $(MSWSYS)/ntsound.c
	$(cc) $(CFLAGS)  -o$@ $(MSWSYS)/ntsound.c


#if you aren't linking in the full gui then
#include the following stub for proper linkage.

$(O)guistub.o: $(HACK_H) $(MSWSYS)/stubs.c
	@$(cc) $(CFLAGS) -DGUISTUB  -o$@ $(MSWSYS)/stubs.c

#if you aren't linking in the full tty then
#include the following stub for proper linkage.

$(O)ttystub.o: $(HACK_H) $(MSWSYS)/stubs.c
	@$(cc) $(CFLAGS) -DTTYSTUB -o$@ $(MSWSYS)/stubs.c

$(O)tile.o: $(SRC)/tile.c $(HACK_H)

#
# util dependencies
#

$(O)panic.o:  $(U)panic.c $(CONFIG_H)
	$(cc) $(CFLAGS) -o$@ $(U)panic.c

#
# The rest are stolen from sys/unix/Makefile.src,
# with the following changes:
#   * ../include changed to $(INCL)
#   * -c (which is included in CFLAGS) substituted
#	with -o$@
#   * targets prefixed with $(O)
#   * $(CC) changed to $(cc)
# but otherwise untouched. 
# That means that there is some irrelevant stuff
# in here, but maintenance should be easier.
#
$(O)tos.o: ../sys/atari/tos.c $(HACK_H) $(INCL)/tcap.h
	$(cc) $(CFLAGS) -o$@ ../sys/atari/tos.c
$(O)pcmain.o: ../sys/share/pcmain.c $(HACK_H) $(INCL)/dlb.h \
		$(INCL)/win32api.h
	$(cc) $(CFLAGS) -o$@ ../sys/share/pcmain.c
$(O)pcsys.o: ../sys/share/pcsys.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/pcsys.c
$(O)pctty.o: ../sys/share/pctty.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/pctty.c
$(O)pcunix.o: ../sys/share/pcunix.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/pcunix.c
$(O)random.o: ../sys/share/random.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/random.c
$(O)ioctl.o: ../sys/share/ioctl.c $(HACK_H) $(INCL)/tcap.h
	$(cc) $(CFLAGS) -o$@ ../sys/share/ioctl.c
$(O)unixtty.o: ../sys/share/unixtty.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/unixtty.c
$(O)unixmain.o: ../sys/unix/unixmain.c $(HACK_H) $(INCL)/dlb.h
	$(cc) $(CFLAGS) -o$@ ../sys/unix/unixmain.c
$(O)unixunix.o: ../sys/unix/unixunix.c $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/unix/unixunix.c
$(O)unixres.o: ../sys/unix/unixres.c $(CONFIG_H)
	$(cc) $(CFLAGS) -o$@ ../sys/unix/unixres.c
$(O)bemain.o: ../sys/be/bemain.c $(HACK_H) $(INCL)/dlb.h
	$(cc) $(CFLAGS) -o$@ ../sys/be/bemain.c
$(O)getline.o: ../win/tty/getline.c $(HACK_H) $(INCL)/func_tab.h
	$(cc) $(CFLAGS) -o$@ ../win/tty/getline.c
$(O)termcap.o: ../win/tty/termcap.c $(HACK_H) $(INCL)/tcap.h
	$(cc) $(CFLAGS) -o$@ ../win/tty/termcap.c
$(O)topl.o: ../win/tty/topl.c $(HACK_H) $(INCL)/tcap.h
	$(cc) $(CFLAGS) -o$@ ../win/tty/topl.c
$(O)wintty.o: ../win/tty/wintty.c $(HACK_H) $(INCL)/dlb.h \
		$(INCL)/date.h $(INCL)/patchlevel.h $(INCL)/tcap.h
	$(cc) $(CFLAGS) -o$@ ../win/tty/wintty.c
$(O)Window.o: ../win/X11/Window.c $(INCL)/xwindowp.h $(INCL)/xwindow.h \
		$(CONFIG_H)
	$(cc) $(CFLAGS) -o$@ ../win/X11/Window.c
$(O)dialogs.o: ../win/X11/dialogs.c $(CONFIG_H)
	$(cc) $(CFLAGS) -o$@ ../win/X11/dialogs.c
$(O)winX.o: ../win/X11/winX.c $(HACK_H) $(INCL)/winX.h $(INCL)/dlb.h \
		$(INCL)/patchlevel.h ../win/X11/nh72icon \
		../win/X11/nh56icon ../win/X11/nh32icon
	$(cc) $(CFLAGS) -o$@ ../win/X11/winX.c
$(O)winmap.o: ../win/X11/winmap.c $(INCL)/xwindow.h $(HACK_H) $(INCL)/dlb.h \
		$(INCL)/winX.h $(INCL)/tile2x11.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winmap.c
$(O)winmenu.o: ../win/X11/winmenu.c $(HACK_H) $(INCL)/winX.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winmenu.c
$(O)winmesg.o: ../win/X11/winmesg.c $(INCL)/xwindow.h $(HACK_H) $(INCL)/winX.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winmesg.c
$(O)winmisc.o: ../win/X11/winmisc.c $(HACK_H) $(INCL)/func_tab.h \
		$(INCL)/winX.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winmisc.c
$(O)winstat.o: ../win/X11/winstat.c $(HACK_H) $(INCL)/winX.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winstat.c
$(O)wintext.o: ../win/X11/wintext.c $(HACK_H) $(INCL)/winX.h $(INCL)/xwindow.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/wintext.c
$(O)winval.o: ../win/X11/winval.c $(HACK_H) $(INCL)/winX.h
	$(cc) $(CFLAGS) -o$@ ../win/X11/winval.c
$(O)tile.o: $(SRC)/tile.c $(HACK_H)
$(O)gnaskstr.o: ../win/gnome/gnaskstr.c ../win/gnome/gnaskstr.h \
		../win/gnome/gnmain.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnaskstr.c
$(O)gnbind.o: ../win/gnome/gnbind.c ../win/gnome/gnbind.h ../win/gnome/gnmain.h \
		../win/gnome/gnaskstr.h ../win/gnome/gnyesno.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnbind.c
$(O)gnglyph.o: ../win/gnome/gnglyph.c ../win/gnome/gnglyph.h $(INCL)/tile2x11.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnglyph.c
$(O)gnmain.o: ../win/gnome/gnmain.c ../win/gnome/gnmain.h ../win/gnome/gnsignal.h \
		../win/gnome/gnbind.h ../win/gnome/gnopts.h $(HACK_H) \
		$(INCL)/date.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnmain.c
$(O)gnmap.o: ../win/gnome/gnmap.c ../win/gnome/gnmap.h ../win/gnome/gnglyph.h \
		../win/gnome/gnsignal.h $(HACK_H)
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnmap.c
$(O)gnmenu.o: ../win/gnome/gnmenu.c ../win/gnome/gnmenu.h ../win/gnome/gnmain.h \
		../win/gnome/gnbind.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnmenu.c
$(O)gnmesg.o: ../win/gnome/gnmesg.c ../win/gnome/gnmesg.h ../win/gnome/gnsignal.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnmesg.c
$(O)gnopts.o: ../win/gnome/gnopts.c ../win/gnome/gnopts.h ../win/gnome/gnglyph.h \
		../win/gnome/gnmain.h ../win/gnome/gnmap.h $(HACK_H)
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnopts.c
$(O)gnplayer.o: ../win/gnome/gnplayer.c ../win/gnome/gnplayer.h \
		../win/gnome/gnmain.h $(HACK_H)
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnplayer.c
$(O)gnsignal.o: ../win/gnome/gnsignal.c ../win/gnome/gnsignal.h \
		../win/gnome/gnmain.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnsignal.c
$(O)gnstatus.o: ../win/gnome/gnstatus.c ../win/gnome/gnstatus.h \
		../win/gnome/gnsignal.h ../win/gnome/gn_xpms.h \
		../win/gnome/gnomeprv.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnstatus.c
$(O)gntext.o: ../win/gnome/gntext.c ../win/gnome/gntext.h ../win/gnome/gnmain.h \
		../win/gnome/gn_rip.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gntext.c
$(O)gnworn.o: ../win/gnome/gnworn.c ../win/gnome/gnworn.h ../win/gnome/gnglyph.h \
		../win/gnome/gnsignal.h ../win/gnome/gnomeprv.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnworn.c
$(O)gnyesno.o: ../win/gnome/gnyesno.c ../win/gnome/gnbind.h ../win/gnome/gnyesno.h
	$(cc) $(CFLAGS) $(GNOMEINC) -o$@ ../win/gnome/gnyesno.c
$(O)wingem.o: ../win/gem/wingem.c $(HACK_H) $(INCL)/func_tab.h $(INCL)/dlb.h \
		$(INCL)/patchlevel.h $(INCL)/wingem.h
	$(cc) $(CFLAGS) -o$@ ../win/gem/wingem.c
$(O)wingem1.o: ../win/gem/wingem1.c $(INCL)/gem_rsc.h $(INCL)/load_img.h \
		$(INCL)/gr_rect.h $(INCL)/wintype.h $(INCL)/wingem.h
	$(cc) $(CFLAGS) -o$@ ../win/gem/wingem1.c
$(O)load_img.o: ../win/gem/load_img.c $(INCL)/load_img.h
	$(cc) $(CFLAGS) -o$@ ../win/gem/load_img.c
$(O)gr_rect.o: ../win/gem/gr_rect.c $(INCL)/gr_rect.h
	$(cc) $(CFLAGS) -o$@ ../win/gem/gr_rect.c
$(O)qt_win.o: ../win/Qt/qt_win.cpp $(HACK_H) $(INCL)/func_tab.h \
		$(INCL)/dlb.h $(INCL)/patchlevel.h $(INCL)/tile2x11.h \
		$(INCL)/qt_win.h $(INCL)/qt_clust.h $(INCL)/qt_kde0.h \
		$(INCL)/qt_xpms.h qt_win.moc qt_kde0.moc qttableview.moc
	$(CXX) $(CXXFLAGS) -o$@ ../win/Qt/qt_win.cpp
$(O)qt_clust.o: ../win/Qt/qt_clust.cpp $(INCL)/qt_clust.h
	$(CXX) $(CXXFLAGS) -o$@ ../win/Qt/qt_clust.cpp
$(O)qttableview.o: ../win/Qt/qttableview.cpp $(INCL)/qttableview.h
	$(CXX) $(CXXFLAGS) -o$@ ../win/Qt/qttableview.cpp
$(O)monstr.o: monstr.c $(CONFIG_H)
$(O)vis_tab.o: vis_tab.c $(CONFIG_H) $(INCL)/vis_tab.h
$(O)allmain.o: allmain.c $(HACK_H)
$(O)alloc.o: alloc.c $(CONFIG_H)
$(O)apply.o: apply.c $(HACK_H)
$(O)artifact.o: artifact.c $(HACK_H) $(INCL)/artifact.h $(INCL)/artilist.h
$(O)attrib.o: attrib.c $(HACK_H)
$(O)ball.o: ball.c $(HACK_H)
$(O)bones.o: bones.c $(HACK_H) $(INCL)/lev.h
$(O)botl.o: botl.c $(HACK_H)
$(O)cmd.o: cmd.c $(HACK_H) $(INCL)/func_tab.h
$(O)dbridge.o: dbridge.c $(HACK_H)
$(O)decl.o: decl.c $(HACK_H)
$(O)detect.o: detect.c $(HACK_H) $(INCL)/artifact.h
$(O)dig.o: dig.c $(HACK_H)
$(O)display.o: display.c $(HACK_H)
$(O)dlb.o: dlb.c $(CONFIG_H) $(INCL)/dlb.h
$(O)do.o: do.c $(HACK_H) $(INCL)/lev.h
$(O)do_name.o: do_name.c $(HACK_H)
$(O)do_wear.o: do_wear.c $(HACK_H)
$(O)dog.o: dog.c $(HACK_H)
$(O)dogmove.o: dogmove.c $(HACK_H) $(INCL)/mfndpos.h
$(O)dokick.o: dokick.c $(HACK_H)
$(O)dothrow.o: dothrow.c $(HACK_H)
$(O)drawing.o: drawing.c $(HACK_H) $(INCL)/tcap.h
$(O)dungeon.o: dungeon.c $(HACK_H) $(INCL)/dgn_file.h $(INCL)/dlb.h
$(O)eat.o: eat.c $(HACK_H)
$(O)end.o: end.c $(HACK_H) $(INCL)/lev.h $(INCL)/dlb.h
$(O)engrave.o: engrave.c $(HACK_H) $(INCL)/lev.h
$(O)exper.o: exper.c $(HACK_H)
$(O)explode.o: explode.c $(HACK_H)
$(O)extralev.o: extralev.c $(HACK_H)
$(O)files.o: files.c $(HACK_H) $(INCL)/dlb.h
$(O)fountain.o: fountain.c $(HACK_H)
$(O)hack.o: hack.c $(HACK_H)
$(O)hacklib.o: hacklib.c $(HACK_H)
$(O)invent.o: invent.c $(HACK_H)
$(O)light.o: light.c $(HACK_H) $(INCL)/lev.h
$(O)lock.o: lock.c $(HACK_H)
$(O)mail.o: mail.c $(HACK_H) $(INCL)/mail.h
$(O)makemon.o: makemon.c $(HACK_H)
$(O)mapglyph.o: mapglyph.c $(HACK_H)
$(O)mcastu.o: mcastu.c $(HACK_H)
$(O)mhitm.o: mhitm.c $(HACK_H) $(INCL)/artifact.h
$(O)mhitu.o: mhitu.c $(HACK_H) $(INCL)/artifact.h
$(O)minion.o: minion.c $(HACK_H)
$(O)mklev.o: mklev.c $(HACK_H)
$(O)mkmap.o: mkmap.c $(HACK_H) $(INCL)/sp_lev.h
$(O)mkmaze.o: mkmaze.c $(HACK_H) $(INCL)/sp_lev.h $(INCL)/lev.h
$(O)mkobj.o: mkobj.c $(HACK_H)
$(O)mkroom.o: mkroom.c $(HACK_H)
$(O)mon.o: mon.c $(HACK_H) $(INCL)/mfndpos.h
$(O)mondata.o: mondata.c $(HACK_H)
$(O)monmove.o: monmove.c $(HACK_H) $(INCL)/mfndpos.h $(INCL)/artifact.h
$(O)monst.o: monst.c $(CONFIG_H) $(INCL)/permonst.h $(INCL)/align.h \
		$(INCL)/monattk.h $(INCL)/monflag.h $(INCL)/monsym.h \
		$(INCL)/color.h
$(O)mplayer.o: mplayer.c $(HACK_H)
$(O)mthrowu.o: mthrowu.c $(HACK_H)
$(O)muse.o: muse.c $(HACK_H)
$(O)music.o: music.c $(HACK_H) #interp.c
$(O)o_init.o: o_init.c $(HACK_H) $(INCL)/lev.h
$(O)objects.o: objects.c $(CONFIG_H) $(INCL)/obj.h $(INCL)/objclass.h \
		$(INCL)/prop.h $(INCL)/skills.h $(INCL)/color.h
$(O)objnam.o: objnam.c $(HACK_H)
$(O)options.o: options.c $(CONFIG_H) $(INCL)/objclass.h $(INCL)/flag.h \
		$(HACK_H) $(INCL)/tcap.h
$(O)pager.o: pager.c $(HACK_H) $(INCL)/dlb.h
$(O)pickup.o: pickup.c $(HACK_H)
$(O)pline.o: pline.c $(HACK_H)
$(O)polyself.o: polyself.c $(HACK_H)
$(O)potion.o: potion.c $(HACK_H)
$(O)pray.o: pray.c $(HACK_H)
$(O)priest.o: priest.c $(HACK_H) $(INCL)/mfndpos.h
$(O)quest.o: quest.c $(HACK_H) $(INCL)/qtext.h
$(O)questpgr.o: questpgr.c $(HACK_H) $(INCL)/dlb.h $(INCL)/qtext.h
$(O)read.o: read.c $(HACK_H)
$(O)rect.o: rect.c $(HACK_H)
$(O)region.o: region.c $(HACK_H) $(INCL)/lev.h
$(O)restore.o: restore.c $(HACK_H) $(INCL)/lev.h $(INCL)/tcap.h
$(O)rip.o: rip.c $(HACK_H)
$(O)rnd.o: rnd.c $(HACK_H)
$(O)role.o: role.c $(HACK_H)
$(O)rumors.o: rumors.c $(HACK_H) $(INCL)/lev.h $(INCL)/dlb.h
$(O)save.o: save.c $(HACK_H) $(INCL)/lev.h
$(O)shk.o: shk.c $(HACK_H)
$(O)shknam.o: shknam.c $(HACK_H)
$(O)sit.o: sit.c $(HACK_H) $(INCL)/artifact.h
$(O)sounds.o: sounds.c $(HACK_H)
$(O)sp_lev.o: sp_lev.c $(HACK_H) $(INCL)/dlb.h $(INCL)/sp_lev.h
$(O)spell.o: spell.c $(HACK_H)
$(O)steal.o: steal.c $(HACK_H)
$(O)steed.o: steed.c $(HACK_H)
$(O)sys.o: sys.c $(HACK_H)
$(O)teleport.o: teleport.c $(HACK_H)
$(O)timeout.o: timeout.c $(HACK_H) $(INCL)/lev.h
$(O)topten.o: topten.c $(HACK_H) $(INCL)/dlb.h $(INCL)/patchlevel.h
$(O)track.o: track.c $(HACK_H)
$(O)trap.o: trap.c $(HACK_H)
$(O)u_init.o: u_init.c $(HACK_H)
$(O)uhitm.o: uhitm.c $(HACK_H)
$(O)vault.o: vault.c $(HACK_H)
$(O)version.o: version.c $(HACK_H) $(INCL)/date.h $(INCL)/patchlevel.h
$(O)vision.o: vision.c $(HACK_H) $(INCL)/vis_tab.h
$(O)weapon.o: weapon.c $(HACK_H)
$(O)were.o: were.c $(HACK_H)
$(O)wield.o: wield.c $(HACK_H)
$(O)windows.o: windows.c $(HACK_H) $(INCL)/wingem.h $(INCL)/winGnome.h
$(O)wizard.o: wizard.c $(HACK_H) $(INCL)/qtext.h
$(O)worm.o: worm.c $(HACK_H) $(INCL)/lev.h
$(O)worn.o: worn.c $(HACK_H)
$(O)write.o: write.c $(HACK_H)
$(O)zap.o: zap.c $(HACK_H)

# end of file
