#OS=WIN98
#ENV=WIN32
#CPU=i386
#!include <$(OS)$(ENV).MAK>

cpu= -mcpu=i386 -O1

# Use up to date help compiler
#hc="c:\program files\help workshop\hcrtf.exe" -xn


# Uncomment both lines to turn on debugging symbols #######
#cdebug= -g
#linkdebug= -g
#######################################################

proj=winboard
allobj=  winboard.o backend.o parser.o moves.o lists.o \
	 gamelist.o pgntags.o wedittags.o wgamelist.o zippy.o \
         wsockerr.o wbres.o wclipbrd.o woptions.o


# 2 Dec 2001 - the mingw libraries that I have right now
#  (not updated for a few months) have bugs in fileno and stat
#  that prevent WinBoard from working.
#
# Without this option there are problems with sounds.
# Hope it is safe now (18 Aug 2003). AV.
cygwin= -mno-cygwin


CFLAGS= $(cdebug)
CVARS= -I. -mwindows $(cygwin) $(cpu)
CC = gcc $(CVARS)
WCC = $(CC) -mwindows -Xlinker "-e" -Xlinker "_mainCRTStartup" \
  $(linkdebug) $(cygwin)
LD = ld

all: $(proj).exe

# Update the help file if necessary
#	$(proj).hlp : $(proj).rtf
#	$(hc) $(proj).hpj
#	cat $(proj).err

# Update the resource if necessary
wbres.o: $(proj).rc $(proj).h resource.h
	windres --use-temp-file $< -O coff -o $@

# Update the object files if necessary

winboard.o: winboard.c config.h winboard.h common.h frontend.h backend.h \
        moves.h wgamelist.h defaults.h resource.h

backend.o: backend.c config.h frontend.h backend.h common.h parser.h lang.h

parser.o: parser.c config.h common.h backend.h parser.h

parser.c: parser.l
	flex -L parser.l
	cp lex.yy.c parser.c

moves.o: moves.c config.h backend.h common.h parser.h moves.h

lists.o: lists.c config.h lists.h common.h

gamelist.o: gamelist.c config.h lists.h common.h frontend.h backend.h \
        parser.h

pgntags.o: pgntags.c config.h common.h frontend.h backend.h parser.h lists.h

wclipbrd.o: wclipbrd.c config.h common.h winboard.h frontend.h backend.h

wedittags.o: wedittags.c config.h common.h winboard.h frontend.h backend.h

wgamelist.o: wgamelist.c config.h. common.h winboard.h frontend.h backend.h \
        wgamelist.h

woptions.o: woptions.c config.h common.h winboard.h frontend.h backend.h

wsockerr.o: wsockerr.c wsockerr.h

zippy.o: zippy.c config.h common.h zippy.h frontend.h



$(proj).exe: $(allobj) $(proj).hlp $(proj).rc
	$(WCC) $(guiflags) $(allobj) \
	-lwsock32 -lcomctl32 -lwinmm  -lkernel32 \
	-ladvapi32 -luser32 -lgdi32 -lcomdlg32 -lwinspool \
	-o $(proj).exe

clean:
	rm *.o parser.c
