# NetHack 3.6	Makefile.gcc	$NHDT-Date: 1546174698 2018/12/30 12:58:18 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.71 $
# Copyright (c) 2010 by Michael Allison
# NetHack may be freely redistributed.  See license for details.
#
#==============================================================================
#
#   Win32 Compilers Tested with this Makefile.gcc:
#       mingw-w64
#   from:
#       https://sourceforge.net/p/mingw-w64/wiki2/GeneralUsageInstructions/
#           Toolchain for Windows 32-bit target
#
#
#==============================================================================
#   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 4 decisions that you have to make.
#	1. Where do you want your build to end up?
#	2. Do you want debug information in the executable?
#	3. Do you want to explicitly override auto-detection of a 32-bit or 64-bit target?
#       4. Do you want to include any optional interfaces in the port?
#          4a) curses
#          4b) Qt
#-----------------------------------------------------------------------------------------
#=========================================================================================

#==============================================================================
#---------------------------------------------------------------
# 1. Where do you want the game to be built (which folder)?
#    If not present prior to compilation it gets created.
#

GAMEDIR = ../binary

# 1. 32-bit or 64-bit?
#

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

DEBUGINFO = Y

#
#---------------------------------------------------------------
# 3. Do you want to explicitly override auto-detection of a 32-bit
#    or 64-bit executable (save files do not interchange currently)?
#
# 64 bit
#TARGET_CPU=x64
#
# 32 bit
TARGET_CPU=x86
#
#
#---------------------------------------------------------------
# 4. Do you want additional GUI interfaces in the executable?
#    Make these Y to enable the GUIs. Win32 is always enabled,
#    and is the default.
#

#4a Curses window port support
#
#
# 4. Uncomment these and set them appropriately if you want to
#    include curses port support alongside TTY support in your
#    NetHack.exe binary. 
#
#    You'll have to set PDCURSES_H to the correct location of the 
#    PDCurses header (.h) files and PDCURSES_C to the location
#    of your PDCurses C files which must already be resident on 
#    your machine.
#
#ADD_CURSES=Y
#PDCURSES_TOP=../../pdcurses

#4b Qt
#
#WANT_WIN_QT4 = N

# WANT_WIN_QT4 requires Qt 4 or Qt 5, see
# https://www.qt.io/download-open-source/
# Earlier versions of Qt are not compatible with Windows
# For Qt 5, use:
#
#QT4_DIRECTORY = c:/Qt/Qt5.9.2/5.9.2/mingw53_32
#HAVE_QT5 = Y

# For Qt 4, comment out the above two lines and use:
#
#QT4_DIRECTORY = c:/Qt/4.8.6
#HAVE_QT5 = N

#
# Note that additional GUI interfaces may require external libraries.
# Qt is placed where the official installer places it.
# Other libraries are placed in a subdirectory of your home directory, either
# x86libs or x64libs depending on whether you're building for 64 bits.
#

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

SKIP_NETHACKW=Y

#==============================================================================

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

# INCL    - NetHack include files
# DAT     - NetHack data files
# DOC     - NetHack documentation files
# UTIL    - Utility source
# SRC     - Main source
# SSYS    - Shared system files
# MSWSYS  - mswin specific files
# TTY     - window port files (tty)
# MSWIN   - window port files (win32)
# WCURSES - window port files (curses) 
# WSHR    - Tile support files 

INCL    =../include
DAT     =../dat
DOC     =../doc
UTIL    =../util
SRC     =../src
SSYS    =../sys/share
MSWSYS  =../sys/winnt
TTY     =../win/tty
MSWIN   =../win/win32
WCURSES =../win/curses
WSHR    =../win/share

#
#  Object directory.
#

OBJ = o

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

RANDOM  = $(OBJ)/random.o
#RANDOM =
BCRYPT=-lbcrypt

WINPFLAG   = -DTILES -DMSWIN_GRAPHICS -DWIN32CON -D_WIN32_IE=0x0400 -D_WIN32_WINNT=0x0501
ifeq "$(WANT_WIN_QT4)" "Y"
    WINPFLAG += -DQT_GRAPHICS -DPIXMAPDIR='"."'
endif
# 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

#
# If you defined ZLIB_COMP in include/config.h and you need
# to link with the zlib.lib library, uncomment the line below.
# If necessary, prefix explicit path information to the file name
# otherwise it assumes the NetHack src directory.
#

#ZLIB = zlib.lib

# Have windows path styles available for use in commands
W_OBJ     =$(subst /,\, $(OBJ))
W_INCL    =$(subst /,\, $(INCL))
W_DAT     =$(subst /,\, $(DAT))
W_DOC     =$(subst /,\, $(DOC))
W_UTIL    =$(subst /,\, $(UTIL))
W_SRC     =$(subst /,\, $(SRC))
W_SSYS    =$(subst /,\, $(SSYS))
W_MSWSYS  =$(subst /,\, $(MSWSYS))
W_TTY     =$(subst /,\, $(TTY))
W_MSWIN   =$(subst /,\, $(MSWIN))
W_WCURSES =$(subst /,\, $(WCURSES))
W_WSHR    =$(subst /,\, $(WSHR))
W_GAMEDIR =$(subst /,\, $(GAMEDIR))

#==========================================
#================ 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

LEVCOMPOBJS    = $(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)isaac64.o
VOBJ11 = $(O)mcastu.o   $(O)mhitm.o    $(O)mhitu.o    $(O)minion.o
VOBJ12 = $(O)mklev.o    $(O)mkmap.o    $(O)mkmaze.o   $(O)mkobj.o
VOBJ13 = $(O)mkroom.o   $(O)mon.o      $(O)mondata.o  $(O)monmove.o
VOBJ14 = $(O)monst.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
#VOBJ28 = $(O)win10.o

DLBOBJ = $(O)dlb.o

REGEX  = $(O)cppregex.o

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

ifeq "$(ADD_CURSES)" "Y"
CURSESOBJ= $(O)cursdial.o $(O)cursinit.o $(O)cursinvt.o $(O)cursmain.o \
	   $(O)cursmesg.o $(O)cursmisc.o $(O)cursstat.o $(O)curswins.o
else
CURSESOBJ=
endif

SOBJ   = $(O)windmain.o $(O)winnt.o $(O)win10.o \
	$(O)safeproc.o $(O)nhlan.o $(SOUND) 

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) $(VOBJ28) $(VOBJ29) $(REGEX)  \
	 $(CURSESOBJ)

ifneq "$(SKIP_NETHACKW)" "Y"
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

endif

ifeq "$(WANT_WIN_QT4)" "Y"
    GUIOBJ += $(O)qt4bind.o $(O)qt4click.o $(O)qt4clust.o $(O)qt4delay.o \
	$(O)qt4glyph.o $(O)qt4icon.o $(O)qt4inv.o $(O)qt4key.o $(O)qt4line.o \
	$(O)qt4main.o $(O)qt4map.o $(O)qt4menu.o $(O)qt4msg.o $(O)qt4plsel.o \
	$(O)qt4rip.o $(O)qt4set.o $(O)qt4stat.o $(O)qt4str.o $(O)qt4streq.o \
	$(O)qt4svsel.o $(O)qt4win.o $(O)qt4xcmd.o $(O)qt4yndlg.o
endif

ifneq "$(SKIP_NETHACKW)" "Y"
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
endif

ifeq "$(WANT_WIN_QT4)" "Y"
    GUIHDR += $(QT4)/qt4bind.h $(QT4)/qt4click.h $(QT4)/qt4clust.h \
	$(QT4)/qt4delay.h $(QT4)/qt4glyph.h $(QT4)/qt4icon.h $(QT4)/qt4inv.h \
	$(QT4)/qt4kde0.h $(QT4)/qt4key.h $(QT4)/qt4line.h $(QT4)/qt4main.h \
	$(QT4)/qt4map.h $(QT4)/qt4menu.h $(QT4)/qt4msg.h $(QT4)/qt4plsel.h \
	$(QT4)/qt4rip.h $(QT4)/qt4set.h $(QT4)/qt4stat.h $(QT4)/qt4str.h \
	$(QT4)/qt4streq.h $(QT4)/qt4svsel.h $(QT4)/qt4win.h $(QT4)/qt4xcmd.h \
	$(QT4)/qt4yndlg.h
endif

COMCTRL = comctl32.lib

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

ifeq "$(ADD_CURSES)" "Y"
#==========================================
# PDCurses build macros
#==========================================
PDCURSES_CURSES_H	= $(PDCURSES_TOP)/curses.h
PDCURSES_CURSPRIV_H	= $(PDCURSES_TOP)/curspriv.h
PDCURSES_HEADERS	= $(PDCURSES_CURSES_H) $(PDCURSES_CURSPRIV_H)
PDCSRC                  = $(PDCURSES_TOP)/pdcurses
PDCWINCON               = $(PDCURSES_TOP)/wincon
PDCLIBOBJS = $(O)addch.o $(O)addchstr.o $(O)addstr.o $(O)attr.o $(O)beep.o             \
	$(O)bkgd.o $(O)border.o $(O)clear.o $(O)color.o $(O)delch.o $(O)deleteln.o     \
	$(O)deprec.o $(O)getch.o $(O)getstr.o $(O)getyx.o $(O)inch.o $(O)inchstr.o     \
	$(O)initscr.o $(O)inopts.o $(O)insch.o $(O)insstr.o $(O)instr.o $(O)kernel.o   \
	$(O)keyname.o $(O)mouse.o $(O)move.o $(O)outopts.o $(O)overlay.o $(O)pad.o     \
	$(O)panel.o $(O)printw.o $(O)refresh.o $(O)scanw.o $(O)scr_dump.o $(O)scroll.o \
	$(O)slk.o $(O)termattr.o $(O)terminfo.o $(O)touch.o $(O)util.o $(O)window.o    \
	$(O)debug.o

PDCOBJS = $(O)pdcclip.o $(O)pdcdisp.o $(O)pdcgetsc.o $(O)pdckbd.o $(O)pdcscrn.o \
	  $(O)pdcsetsc.o $(O)pdcutil.o

PDCLIB = $(O)pdcurses.a

PDCINCL = -I$(PDCURSES_TOP) -I$(PDCSRC) -I$(PDCWINCON)
else
PDCLIB = 
endif

#==========================================
# 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

#==========================================
# More compiler setup macros
#==========================================
#
ifeq "$(ADD_CURSES)" "Y"
CURSESDEF=-D"CURSES_GRAPHICS" -D"CURSES_BRIEF_INCLUDE"
else
CURSDEF=
CURSESLIB=
endif

ifneq  "$(ADD_CURSES)" "Y"
INCLDIR=-I../include -I../sys/winnt
else
INCLDIR=-I../include -I../sys/winnt
endif

#==========================================
#==========================================
# Setting up the compiler and linker
# macros. All builds include the base ones.
#==========================================
#==========================================

cc     = i686-w64-mingw32-gcc.exe
cxx    = g++
rc     = windres
link   = i686-w64-mingw32-gcc.exe
ifeq "$(WANT_WIN_QT4)" "Y"
    link = g++
endif

cflags = -mms-bitfields $(INCLDIR)
lflags  =
ifeq  "$(DEBUGINFO)" "Y"
cdebug = -g
linkdebug = -g
else
cdebug =
linkdebug =
endif

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

conlibs = -lgdi32 -lwinmm $(BCRYPT)
guilibs = -lcomctl32 -lwinmm
ifeq "$(WANT_WIN_QT4)" "Y"
    # Might be either Qt 4 or Qt 5
    ifeq "$(HAVE_QT5)" "Y"
	guilibs += $(QT4_DIRECTORY)/lib/libQt5Core.a
	guilibs += $(QT4_DIRECTORY)/lib/libQt5Gui.a
	guilibs += $(QT4_DIRECTORY)/lib/libQt5Widgets.a
	conlibs += $(QT4_DIRECTORY)/lib/libQt5Core.a
    else
	guilibs += $(QT4_DIRECTORY)/lib/libQtCore4.a
	guilibs += $(QT4_DIRECTORY)/lib/libQtGui4.a
	conlibs += $(QT4_DIRECTORY)/lib/libQtCore4.a
    endif
endif

#==========================================
# Extra files needed for some ports
#==========================================
EXTRA_FILES =
ifeq "$(WANT_WIN_QT4)" "Y"
    ifeq "$(HAVE_QT5)" "Y"
	EXTRA_FILES += $(GAMEDIR)/Qt5Core.dll
	EXTRA_FILES += $(GAMEDIR)/Qt5Gui.dll
	EXTRA_FILES += $(GAMEDIR)/Qt5Widgets.dll
    else
    # TODO: define QT 4 DLLs here
	EXTRA_FILES += $(GAMEDIR)/QtCore4.dll
	EXTRA_FILES += $(GAMEDIR)/QtGui4.dll
    endif
    EXTRA_FILES += $(GAMEDIR)/rip.xpm
endif

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

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

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

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

CXXFLAGS = $(CFLAGS)

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

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

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

#==========================================
# 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
	$(cxx) $(CXXFLAGS) -std=c++11  -o$@  $<

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

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

#==========================================
# 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$@  $<

#==========================================
# Rules for files in win\curses
#==========================================

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

#==========================================
# Rules for files in PDCurses
#==========================================

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

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

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

#==========================================
# 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
YACC=

#LEX    = lex
#LEX    = flex
LEX=

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

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

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

export YACC
export LEX
export FLEXSKEL
export YTABC
export YTABH
export LEXYYC

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

ifeq "$(HAVE_QT5)" "Y"
QT4_CXXFLAGS = -std=c++11
else
QT4_CXXFLAGS =
endif
$(OBJ)/%.o : $(QT4)/%.cpp
	$(cxx) $(CXXFLAGS) $(QT4_CXXFLAGS) -I$(MSWIN) -I$(QT4_DIRECTORY)/include -o$@  $<

$(QT4)/%.moc : $(QT4)/%.h
	$(QT4_DIRECTORY)\bin\moc -o $@ $<

ifeq "$(SKIP_NETHACKW)" "Y"
NETHACKW_EXE =
else
NETHACKW_EXE = $(GAMEDIR)/NetHack.exe
endif

SHELL=CMD.EXE

#==========================================
#=============== 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: initialchk $(GAMEDIR)/NetHack.exe $(U)uudecode.exe $(O)winres.o \
	$(NETHACKW_EXE) install.tag $(EXTRA_FILES)
	@echo NetHack is up to date.
	@echo Done.


install.tag:  $(DAT)/data    $(DAT)/rumors    $(DAT)/dungeon \
	       $(DAT)/oracles $(DAT)/quest.dat 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 /,\,if not exist $(GAMEDIR)/defaults.nh copy $(MSWSYS)/defaults.nh   $(GAMEDIR)/defaults.nh)
	$(subst /,\,-if not exist $(GAMEDIR)/record. echo.>$(GAMEDIR)/record.)
#
#
	$(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)

sp_lev.tag: 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 > sp_lev.tag)

utility.tag: $(INCL)/date.h $(INCL)/onames.h $(INCL)/pm.h \
	 $(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.
#==========================================

gamedir.tag:
	test -d $(GAMEDIR) || echo creating directory $(W_GAMEDIR)
	test -d $(GAMEDIR) || mkdir $(W_GAMEDIR)
	test -d $(GAMEDIR) && echo directory created > $@

$(GAMEDIR)/NetHack.exe : gamedir.tag $(PDCLIB) $(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 $(PDCLIB) $(conlibs) -static -lstdc++
	$(subst /,\,@if exist install.tag del install.tag)

# NetHackW
# full tty linkage libs:
#    libs: $(LIBS) $(guilibs) $(COMCTRL)
#    objs: $(GAMEOBJ) $(GUIOBJ) $(TTYOBJ) $(O)tile.o $(O)nttty.o
# otherwise:
#    libs: $(LIBS) $(guilibs) $(COMCTRL)
#    objs: $(GAMEOBJ) $(GUIOBJ) $(O)tile.o $(O)ttystub.o

ifneq "$(SKIP_NETHACKW)" "Y"
$(GAMEDIR)/NetHackW.exe : gamedir.tag $(PDCLIB) $(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 $(PDCLIB) $(guilibs) -static -lstdc++
	$(subst /,\,@if exist install.tag del install.tag)
endif

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

$(GAMEDIR)/nhdefkey.dll : $(O)nhdefkey.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 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 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
#==========================================

initialchk: objdir.tag
	@echo ----
	@echo NOTE: This build will include tile support.
	@echo ----

objdir.tag:
	@test -d $(OBJ) || echo creating directory $(OBJ)
	@test -d $(OBJ) || mkdir $(OBJ)
	@test -d $(OBJ) && echo directory created > $@

#==========================================
#=========== 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
	$(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)/vis_tab.h: $(U)makedefs.exe
	$(subst /,\,$(U)makedefs -z)

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

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

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

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

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

$(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)

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

#==========================================
# 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)
	copy NetHack.ico $(W_MSWSYS)\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)lev_yacc.c: $(U)lev_comp.y
	mingw32-make -C ../util -f ../win/win32/levstuff-mingw32.mak $(U)lev_yacc.c

$(U)lev_lex.c: $(HACK_H) $(U)lev_comp.l
	mingw32-make -C ../util -f ../win/win32/levstuff-mingw32.mak $(U)lev_lex.c

$(INCL)/lev_comp.h:
	mingw32-make -C ../include -f ../win/win32/levstuff-mingw32.mak $(INCL)/lev_comp.h

$(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)levcomp.exe: $(LEVCOMPOBJS)
	@echo Linking $@...
	$(link) $(LFLAGSU) -o$@ $(LEVCOMPOBJS)

#==========================================
# Dungeon Compiler Stuff
#==========================================
$(U)dgn_yacc.c: $(U)dgn_comp.y
	mingw32-make -C ../util -f ../win/win32/dgnstuff-mingw32.mak $(U)dgn_yacc.c

$(INCL)/dgn_comp.h:
	mingw32-make -C ../include -f ../win/win32/dgnstuff-mingw32.mak $(INCL)/dgn_comp.h

$(U)dgn_lex.c: $(U)dgn_comp.l
	mingw32-make -C ../util -f ../win/win32/dgnstuff-mingw32.mak $(U)dgn_lex.c

$(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)dgncomp.exe: $(DGNCOMPOBJS)
	@echo Linking $@...
	@echo Linking $@...
	$(link) $(LFLAGSU) -o$@ $(DGNCOMPOBJS)

#=================================================
# For a couple of devteam utilities
#=================================================

$(U)nhsizes.exe: $(O)nhsizes.o
	@echo Linking $@...
	$(link) $(LFLAGSU) -o$@ $(O)nhsizes.o $(O)panic.o $(O)alloc.o$(U)nhsizes.exe: $(O)nhsizes.o

$(U)nhsize2.exe: $(O)nhsizes2.o
	@echo Linking $@...
	$(link) $(LFLAGSU) -o$@ $(O)nhsizes2.o $(O)panic.o $(O)alloc.o

$(O)nhsizes.o: $(CONFIG_H) nhsizes.c
	$(cc) $(CFLAGSU) -o$@ nhsizes.c

$(O)nhsizes2.o: $(CONFIG_H) nhsizes2.c
	$(cc) $(CFLAGSU) -o$@ nhsizes2.c

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


#==========================================
# 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)/keyhelp \
	 $(DAT)/history $(DAT)/opthelp $(DAT)/wizhelp $(DAT)/dungeon \
	 $(DAT)/porthelp $(DAT)/license $(DAT)/engrave $(DAT)/epitaph $(DAT)/bogusmon $(DAT)/tribute 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 keyhelp >>$(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 $(MSWSYS)/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 which may take some time
	$(subst /,\,@$(U)tile2bmp $(TILEBMP16))

#$(TILEBMP32): $(TILEUTIL32) $(TILEFILES32)
#	@echo Creating 32x32 binary tile files which 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) $(MSWSYS)/win32api.h
	$(cc) $(CFLAGS) -mno-ms-bitfields -I$(WSHR) -o$@ $(WSHR)/tile2bmp.c

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

#==========================================
# PDCurses Library
#==========================================

$(O)pdcurses.a : $(PDCLIBOBJS) $(PDCOBJS)
	ar rcs $@ $(PDCLIBOBJS) $(PDCOBJS)

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

spotless: clean
	if exist o\* del /Q o\*
	-test -d o && rd o
	if exist objdir.tag del objdir.tag
	if exist gamedir.tag del gamedir.tag
ifneq "$(W_GAMEDIR)" ""
	if exist $(W_GAMEDIR)\NetHack.exe  del $(W_GAMEDIR)\NetHack.exe
	if exist $(W_GAMEDIR)\nhdefkey.dll del $(W_GAMEDIR)\nhdefkey.dll
	if exist $(W_GAMEDIR)\nh340key.dll del $(W_GAMEDIR)\nh340key.dll
	if exist $(W_GAMEDIR)\nhraykey.dll del $(W_GAMEDIR)\nhraykey.dll
	if exist $(W_GAMEDIR)\NetHack.exe  del $(W_GAMEDIR)\NetHack.exe
	if exist $(W_GAMEDIR)\NetHack.pdb  del $(W_GAMEDIR)\NetHack.pdb
	if exist $(W_GAMEDIR)\nhdat        del $(W_GAMEDIR)\nhdat
endif
ifneq "$(W_SRC)" ""
	if exist $(W_SRC)\vis_tab.c        del $(W_SRC)\vis_tab.c
	if exist $(W_SRC)\tile.c           del $(W_SRC)\tile.c
	if exist $(W_SRC)\vis_tab.c        del $(W_SRC)\vis_tab.c
	if exist nhdat.			   del nhdat.
endif
ifneq "$(W_DAT)" ""
	if exist $(W_DAT)\data             del $(W_DAT)\data
	if exist $(W_DAT)\rumors           del $(W_DAT)\rumors
	if exist $(W_DAT)\engrave          del $(W_DAT)\engrave
	if exist $(W_DAT)\epitaph          del $(W_DAT)\epitaph
	if exist $(W_DAT)\bogusmon         del $(W_DAT)\bogusmon
	if exist $(W_DAT)\???-fil?.lev	   del $(W_DAT)\???-fil?.lev
	if exist $(W_DAT)\???-goal.lev	   del $(W_DAT)\???-goal.lev
	if exist $(W_DAT)\???-loca.lev	   del $(W_DAT)\???-loca.lev
	if exist $(W_DAT)\???-strt.lev	   del $(W_DAT)\???-strt.lev
	if exist $(W_DAT)\air.lev          del $(W_DAT)\air.lev
	if exist $(W_DAT)\asmodeus.lev	   del $(W_DAT)\asmodeus.lev
	if exist $(W_DAT)\astral.lev	   del $(W_DAT)\astral.lev
	if exist $(W_DAT)\baalz.lev	   del $(W_DAT)\baalz.lev
	if exist $(W_DAT)\bigrm-*.lev	   del $(W_DAT)\bigrm-*.lev
	if exist $(W_DAT)\castle.lev	   del $(W_DAT)\castle.lev
	if exist $(W_DAT)\data		   del $(W_DAT)\data
	if exist $(W_DAT)\dungeon          del $(W_DAT)\dungeon
	if exist $(W_DAT)\dungeon.pdf	   del $(W_DAT)\dungeon.pdf
	if exist $(W_DAT)\earth.lev	   del $(W_DAT)\earth.lev
	if exist $(W_DAT)\fakewiz?.lev	   del $(W_DAT)\fakewiz?.lev
	if exist $(W_DAT)\fire.lev	   del $(W_DAT)\fire.lev
	if exist $(W_DAT)\juiblex.lev	   del $(W_DAT)\juiblex.lev
	if exist $(W_DAT)\knox.lev	   del $(W_DAT)\knox.lev
	if exist $(W_DAT)\medusa-?.lev	   del $(W_DAT)\medusa-?.lev
	if exist $(W_DAT)\mine*.lev	   del $(W_DAT)\mine*.lev
	if exist $(W_DAT)\options          del $(W_DAT)\options
	if exist $(W_DAT)\ttyoptions	   del $(W_DAT)\ttyoptions
	if exist $(W_DAT)\guioptions       del $(W_DAT)\guioptions
	if exist $(W_DAT)\oracle.lev       del $(W_DAT)\oracle.lev
	if exist $(W_DAT)\oracles          del $(W_DAT)\oracles
	if exist $(W_DAT)\orcus.lev	   del $(W_DAT)\orcus.lev
	if exist $(W_DAT)\rumors           del $(W_DAT)\rumors
	if exist $(W_DAT)\quest.dat	   del $(W_DAT)\quest.dat
	if exist $(W_DAT)\sanctum.lev	   del $(W_DAT)\sanctum.lev
	if exist $(W_DAT)\soko?-?.lev	   del $(W_DAT)\soko?-?.lev
	if exist $(W_DAT)\tower?.lev	   del $(W_DAT)\tower?.lev
	if exist $(W_DAT)\valley.lev	   del $(W_DAT)\valley.lev
	if exist $(W_DAT)\water.lev	   del $(W_DAT)\water.lev
	if exist $(W_DAT)\wizard?.lev	   del $(W_DAT)\wizard?.lev
	if exist $(W_DAT)\dlb.lst          del $(W_DAT)\dlb.lst
	if exist $(W_DAT)\porthelp	   del $(W_DAT)\porthelp
endif
ifneq "$(W_OBJ)" ""
	if exist $(W_OBJ)\sp_lev.tag	   del $(W_OBJ)\sp_lev.tag
	if exist $(W_OBJ)\obj.tag          del $(W_OBJ)\obj.tag
	if exist $(W_OBJ)\gamedir.tag      del $(W_OBJ)\gamedir.tag
	if exist $(W_OBJ)\nh*key.lib       del $(W_OBJ)\nh*key.lib
	if exist $(W_OBJ)\nh*key.exp       del $(W_OBJ)\nh*key.exp
endif
ifneq "$(W_MSWIN)" ""
	if exist $(W_MSWIN)\mnsel.bmp      del $(W_MSWIN)\mnsel.bmp
	if exist $(W_MSWIN)\mnselcnt.bmp   del $(W_MSWIN)\mnselcnt.bmp
	if exist $(W_MSWIN)\mnunsel.bmp    del $(W_MSWIN)\mnunsel.bmp
	if exist $(W_MSWIN)\petmark.bmp    del $(W_MSWIN)\petmark.bmp
	if exist $(W_MSWIN)\pilemark.bmp   del $(W_MSWIN)\pilemark.bmp
	if exist $(W_MSWIN)\rip.bmp        del $(W_MSWIN)\rip.bmp
	if exist $(W_MSWIN)\splash.bmp     del $(W_MSWIN)\splash.bmp
	if exist $(W_MSWIN)\nethack.ico    del $(W_MSWIN)\nethack.ico
endif
ifneq "$(W_MSWSYS)" ""
	if exist $(W_MSWSYS)\nethack.ico   del $(W_MSWSYS)\nethack.ico
endif
ifneq "$(W_UTIL)" ""
	if exist $(W_UTIL)\*.lnk           del $(W_UTIL)\*.lnk
	if exist $(W_UTIL)\*.map           del $(W_UTIL)\*.map
	if exist $(W_UTIL)\recover.exe     del $(W_UTIL)\recover.exe
	if exist $(W_UTIL)\tile2bmp.exe    del $(W_UTIL)\tile2bmp.exe
	if exist $(W_UTIL)\tilemap.exe     del $(W_UTIL)\tilemap.exe
	if exist $(W_UTIL)\uudecode.exe    del $(W_UTIL)\uudecode.exe
	if exist $(W_UTIL)\dlb_main.exe    del $(W_UTIL)\dlb_main.exe
endif
ifneq "$(W_INCL)" ""
	if exist $(W_INCL)\date.h          del $(W_INCL)\date.h
	if exist $(W_INCL)\onames.h        del $(W_INCL)\onames.h
	if exist $(W_INCL)\pm.h            del $(W_INCL)\pm.h
	if exist $(W_INCL)\vis_tab.h       del $(W_INCL)\vis_tab.h
endif
ifeq "$(ADD_CURSES)" "Y"
ifneq "$(W_OBJ)" ""
	if exist $(W_OBJ)\pdcurses.lib     del $(W_OBJ)\pdcurses.lib
endif
endif
	if exist $(W_GAMEDIR)\license. del $(W_GAMEDIR)\license.
	if exist $(W_GAMEDIR)\nh340key.dll del $(W_GAMEDIR)\nh340key.dll
	if exist $(W_GAMEDIR)\nhdefkey.dll del $(W_GAMEDIR)\nhdefkey.dll
	if exist $(W_GAMEDIR)\nhraykey.dll del $(W_GAMEDIR)\nhraykey.dll
	-test -d ..\binary && rd ..\binary

clean:
	if exist initialchk del initialchk
	if exist install.tag del install.tag
	if exist utility.tag del utility.tag
ifneq "$(W_UTIL)" ""
	if exist $(W_UTIL)\makedefs.exe    del $(W_UTIL)\makedefs.exe
	if exist $(W_UTIL)\levcomp.exe     del $(W_UTIL)\levcomp.exe
	if exist $(W_UTIL)\dgncomp.exe     del $(W_UTIL)\dgncomp.exe
endif
ifneq "$(W_SRC)" ""
	if exist $(W_SRC)\*.lnk            del $(W_SRC)\*.lnk
	if exist $(W_SRC)\*.map            del $(W_SRC)\*.map
endif
ifneq "$(W_OBJ)" ""
	if exist $(W_OBJ)\*.o              del $(W_OBJ)\*.o
	if exist $(W_OBJ)\utility.tag      del $(W_OBJ)\utility.tag
	if exist $(W_OBJ)\install.tag      del $(W_OBJ)\install.tag
	if exist $(W_OBJ)\console.res      del $(W_OBJ)\console.res
	if exist $(W_OBJ)\dgncomp.MAP      del $(W_OBJ)\dgncomp.MAP
	if exist $(W_OBJ)\dgncomp.PDB      del $(W_OBJ)\dgncomp.PDB
	if exist $(W_OBJ)\dlb_main.MAP     del $(W_OBJ)\dlb_main.MAP
	if exist $(W_OBJ)\dlb_main.PDB     del $(W_OBJ)\dlb_main.PDB
	if exist $(W_OBJ)\gamedir.tag      del $(W_OBJ)\gamedir.tag
	if exist $(W_OBJ)\levcomp.MAP      del $(W_OBJ)\levcomp.MAP
	if exist $(W_OBJ)\levcomp.PDB      del $(W_OBJ)\levcomp.PDB
	if exist $(W_OBJ)\makedefs.MAP     del $(W_OBJ)\makedefs.MAP
	if exist $(W_OBJ)\makedefs.PDB     del $(W_OBJ)\makedefs.PDB
	if exist $(W_OBJ)\NetHack.MAP      del $(W_OBJ)\NetHack.MAP
	if exist $(W_OBJ)\nh340key.def     del $(W_OBJ)\nh340key.def
	if exist $(W_OBJ)\nh340key.exp     del $(W_OBJ)\nh340key.exp
	if exist $(W_OBJ)\nh340key.lib     del $(W_OBJ)\nh340key.lib
	if exist $(W_OBJ)\nh340key.map     del $(W_OBJ)\nh340key.map
	if exist $(W_OBJ)\nh340key.PDB     del $(W_OBJ)\nh340key.PDB
	if exist $(W_OBJ)\nhdefkey.def     del $(W_OBJ)\nhdefkey.def
	if exist $(W_OBJ)\nhdefkey.exp     del $(W_OBJ)\nhdefkey.exp
	if exist $(W_OBJ)\nhdefkey.lib     del $(W_OBJ)\nhdefkey.lib
	if exist $(W_OBJ)\nhdefkey.map     del $(W_OBJ)\nhdefkey.map
	if exist $(W_OBJ)\nhdefkey.PDB     del $(W_OBJ)\nhdefkey.PDB
	if exist $(W_OBJ)\nhraykey.def     del $(W_OBJ)\nhraykey.def
	if exist $(W_OBJ)\nhraykey.exp     del $(W_OBJ)\nhraykey.exp
	if exist $(W_OBJ)\nhraykey.lib     del $(W_OBJ)\nhraykey.lib
	if exist $(W_OBJ)\nhraykey.map     del $(W_OBJ)\nhraykey.map
	if exist $(W_OBJ)\nhraykey.PDB     del $(W_OBJ)\nhraykey.PDB
	if exist $(W_OBJ)\envchk.tag       del $(W_OBJ)\envchk.tag
	if exist $(W_OBJ)\obj.tag          del $(W_OBJ)\obj.tag
	if exist $(W_OBJ)\sp_lev.tag       del $(W_OBJ)\sp_lev.tag
	if exist $(W_OBJ)\uudecode.MAP     del $(W_OBJ)\uudecode.MAP
	if exist $(W_OBJ)\uudecode.PDB     del $(W_OBJ)\uudecode.PDB
endif
	rem
	rem defer to the steps in ../win/win32/levstuff-mingw32.mak
	rem 
	mingw32-make -f ../win/win32/levstuff-mingw32.mak clean
	rem
	rem defer to the steps in ../win/win32/dgnstuff-mingw32.mak
	mingw32-make -f ../win/win32/dgnstuff-mingw32.mak clean
	$(subst /,\,if exist $(TILEBMP16) del $(TILEBMP16))
	$(subst /,\,if exist $(TILEBMP32) del $(TILEBMP32))

#clean:
#	-test -f install.tag && del install.tag
#	-test -f utility.tag && del utility.tag
#	-test -f $(U)makedefs.exe && del $(U)makedefs.exe
#	-test -f $(U)levcomp.exe && del $(U)levcomp.exe
#	-test -f $(U)dgncomp.exe && del $(U)dgncomp.exe
#	-del $(SRC)/*.lnk
#	-del $(SRC)/*.map
#	-test -f $(TILEBMP16) && del $(TILEBMP16)
#	-test -f $(TILEBMP32) && del $(TILEBMP32)
# 
#===================================================================
# OTHER DEPENDENCIES
#===================================================================
#
# NT dependencies
#

$(O)nttty.o:   $(HACK_H) $(TILE_H) $(MSWSYS)/win32api.h $(MSWSYS)/nttty.c
	$(cc) $(CFLAGS) -I$(WSHR) -o$@  $(MSWSYS)/nttty.c
$(O)winnt.o: $(HACK_H) $(MSWSYS)/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

# 
# sys/share dependencies
#

(O)cppregex.o:	$(O)cppregex.cpp $(HACK_H)
	$(cc) $(CFLAGS) -o$@ ../sys/share/cppregex.cpp

#
# Other dependencies needed by some ports
# 

ifeq "$(ADD_CURSES)" "Y"
# curses window port dependencies
$(O)cursdial.o: $(WCURSES)/cursdial.c $(WCURSES)/cursdial.h $(INCL)/wincurs.h
$(O)cursinit.o: $(WCURSES)/cursinit.c $(WCURSES)/cursinit.h $(INCL)/wincurs.h
$(O)cursinvt.o: $(WCURSES)/cursinvt.c $(WCURSES)/cursinvt.h $(INCL)/wincurs.h
$(O)cursmain.o: $(WCURSES)/cursmain.c $(INCL)/wincurs.h
$(O)cursmesg.o: $(WCURSES)/cursmesg.c $(WCURSES)/cursmesg.h $(INCL)/wincurs.h
$(O)cursmisc.o: $(WCURSES)/cursmisc.c $(WCURSES)/cursmisc.h $(INCL)/wincurs.h
$(O)cursstat.o: $(WCURSES)/cursstat.c $(WCURSES)/cursstat.h $(INCL)/wincurs.h
$(O)curswins.o: $(WCURSES)/curswins.c $(WCURSES)/curswins.h $(INCL)/wincurs.h
endif

ifeq "$(WANT_WIN_QT4)" "Y"
# Qt dependencies

$(GAMEDIR))/Qt5Core.dll : $(QT4_DIRECTORY)/bin/Qt5Core.dll
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR))/Qt5Gui.dll : $(QT4_DIRECTORY)/bin/Qt5Gui.dll
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR)/Qt5Widgets.dll : $(QT4_DIRECTORY)/bin/Qt5Widgets.dll
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR)/QtCore4.dll : $(QT4_DIRECTORY)/bin/QtCore4.dll
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR)/QtGui4.dll : $(QT4_DIRECTORY)/bin/QtGui4.dll
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR)/nhtiles.bmp : $(SRC)/tiles.bmp
	$(subst /,\,@copy $< $@ >nul)

$(GAMEDIR)/rip.xpm : ../win/X11/rip.xpm
	$(subst /,\,@copy $< $@ >nul)
# Dependencies on .moc files (for Qt 4 or 5)
$(OBJ)/qt4main.o : $(QT4)/qt4main.cpp $(QT4)/qt4main.moc $(QT4)/qt4kde0.moc
$(OBJ)/qt4map.o : $(QT4)/qt4map.cpp $(QT4)/qt4map.moc
$(OBJ)/qt4menu.o : $(QT4)/qt4menu.cpp $(QT4)/qt4menu.moc
$(OBJ)/qt4msg.o : $(QT4)/qt4msg.cpp $(QT4)/qt4msg.moc
$(OBJ)/qt4plsel.o : $(QT4)/qt4plsel.cpp $(QT4)/qt4plsel.moc
$(OBJ)/qt4set.o : $(QT4)/qt4set.cpp $(QT4)/qt4set.moc
$(OBJ)/qt4stat.o : $(QT4)/qt4stat.cpp $(QT4)/qt4stat.moc
$(OBJ)/qt4xcmd.o : $(QT4)/qt4xcmd.cpp $(QT4)/qt4xcmd.moc
$(OBJ)/qt4yndlg.o : $(QT4)/qt4yndlg.cpp $(QT4)/qt4yndlg.moc
endif

#
# 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 \
		$(MSWSYS)/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)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
