#
# Makefile for GNU Chess
#
# Copyright (c) 1992, 1994 Free Software Foundation
#
# This file is part of GNU CHESS.
#
# GNU Chess is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Chess is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Chess; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#

# ********************************************************************
# *** This makefile is for use with "nmake" and the C compiler in  ***
# *** the Windows NT SDK from Microsoft.  It builds a version of   ***
# *** GNU Chess that runs under Windows NT or Windows 95 (beta 2), ***
# *** and works with the WinBoard front end (version 3.2.pl2 and   ***
# *** later ONLY).                                                 ***
# ********************************************************************
#
# gnuchessr is a plain dumb-terminal chess (but with full variation output)
# gnuchessx is the same, but suitable for use with WinBoard
# The other versions of gnuchess have not been ported.
# The other gnuchess tools (such as gnuan) have not been ported.
# The gnuchess book is built, but the eco database is not.

# The version number of this GNU release
VERS=	4.0

# size of book to make
# Listed below are the book options and the size of the resulting book,
# the default is small. Uncomment/comment the BOOKOPTS corresponding to
# the size you want.
#
#huge         1,450K
#BOOKOPTS=-S 188000 -P 26
#big            540K
#BOOKOPTS=-S 45000 -P 16
#med            240K
BOOKOPTS=-S 20000 -P 12
#small          144K
BOOKOPTS=-S 12000 -P 10
#tiny            78K
#BOOKOPTS=-S 9000 -P 8
 
BOOK=..\book\gnuchess.bk3.gz

# Where the binaries live.
BINDIR= .

# Where language description, our book, and the persistent hash live.
LIBDIR= .

# Table limits from gnuchess.h. These are given default values if not
# set here. The default values are given below, but you may want to
# check gnuchess.h to make sure.
# -Dttblsz=150001 Transposition table size. Small address space computers
#                 might try 8001. Setting ttblsz to 0 removes the transposition
#                 table
# -DBOOKSIZE=250000 Number of unique position/move combinations allowed.
#                   For MSDOS 10000 is used.

#compile options for gnuchess
# -DBAREBONES compile for max speed no statistics etc kept
# -DECO if you want support for eco database
# -DQUIETBACKGROUND don't print post information in background ( easy OFF)
# -DHAVE_MEMSET if your machine have memset
# -DNOMATERIAL don't call it a draw when no pawns and both sides < rook
# -DNODYNALPHA don't dynamically adjust alpha
# -DHASHSTATS keep hash table statistics
# -DMORESTATS print more hash table stats
# -DHISTORY use history killer hueristic 
# -DKILLT use killt killer hueristic 
# -DHAVE_GETTIMEOFDAY use gettimeofday for more accurate timing
# -DHAVE_TIME_H have <time.h> header
# -DHAVE_STRTOUL if your machine supports strtoul() else strtol()
# -DOLDTIME use old ply time estimating function
# -DCLIENT create client version for use with ICS
# -DOLDXBOARD don't generate underpromote moves
# -DLONG64 if you have 64bit longs
# -DSYSV   if you are using SYSV
# -DCACHE  Cache static evaluations 
# -DQUIETBOOKGEN Don't print errors while loading a book or generating a binbook
# -DSEMIQUIETBOOKGEN Print less verbose errors while reading book or generating binbook
# -DNULLMOVE include null move heuristic
# -DDEEPNULL include deepnull move heuristic
# -DNODITHER no random element to evalustions
# some debug options
# -DDEBUG8 dump board,movelist,input move to /tmp/DEBUG if illegal move
# -DDEBUG9 dump move list from test command
# -DDEBUG10 dump board and move after search before !easy begins
# -DDEBUG11 dump board when the move is output
# -DDEBUG12 dump boards between moves
# -DDEBUG13 dump search control information for each move to /tmp/DEBUG
# -DDEBUG33 dump book moves as read from book
# -DDEBUG40 include extra values of variables for debugging  in game list
# -DDEBUG41 dump post output to /tmp/DEBUG
# the rest of the debug options are tied to the debuglevel command
# -DDEBUG sets up code for debuglevel command
#          debuglevel
#               1 always force evaluation in evaluate
#               4 print move list after search
#               8 print move list after book before search
#              16 print move list after each ply of search
#              32 print adds to transposition table
#              64 print returns from transposition table lookups
#	      128 print evals
#	      256 print search tree as it is generated
#	      512 debug trace of search tree
#	     1024 interactive tree print
#     prints:
# move goal-depth depth ply tree-index flags node-score score alpha beta best movegen-score
#
#example:
#
#debug?p3
#debug?e2e3
#debug?g2e3
#debug?
#
#Move# 1    Target= 0    Clock: 0
#        f2e3 S2 d0 p3 71 200 n->s176 s-179 a343 b512 best-179 x369
#        a6h6 S2 d0 p3 72 200 n->s-802 s-179 a343 b512 best176 x369
#    g2e3 S2 d1 p2 34 200 n->s-176 s-410 a-512 b-343 best-12000 x369
#e2e3 S2 d2 p1 17 0 n->s175 s422 a343 b512 best343 x369
#
#		debug? p#  where # is no. of plys to print 
#				from top of tree (default all plys)
#		       XXXX moves specifying branch of tree to print 
#				(default all branches)
#			       return terminates input
#	     2048 non-interactive trace print

OPT=  -DUSEINT -DCACHE -DGDX -DNULLMOVE -DQUIETBACKGROUND -DWAY4PL64 -DHISTORY -DHASHSTATS -DAGING -DKILLT -DHAVE_MEMSET -DBOOKSIZE=30000 -Dttblsz=8001

# The compiler used for compiling this software.
CC= cl386 -DWIN32 -D_POSIX_ -D__STDC__ -c -W3 -D_X86=1 -Zi -Od $(OPT)
LINK= link32 -debug:full -debugtype:cv -align:0x1000 -subsystem:console
LIBS= libc.lib kernel32.lib

all: gnuchessx.exe gnuchessr.exe gnuchess.data

gnuan.exe: mainN.obj bookG.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchG.obj gnuan.obj
	$(LINK) -out:gnuan.exe mainN.obj bookG.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchG.obj gnuan.obj $(LIBS)

gnuchessx.exe: mainX.obj bookX.obj genmovesX.obj ataks.obj utilX.obj evalX.obj init.obj searchX.obj dspcomX.obj nondspX.obj
	$(LINK) -out:gnuchessx.exe mainX.obj bookX.obj genmovesX.obj ataks.obj utilX.obj evalX.obj init.obj searchX.obj dspcomX.obj nondspX.obj $(LIBS)

ecor.exe: mainN.obj eco.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchN.obj dspcomR.obj nondspR.obj
	$(LINK) -out:ecor.exe mainN.obj eco.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchN.obj dspcomR.obj nondspR.obj $(LIBS)

gnuchessr.exe: mainN.obj bookN.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchN.obj dspcomR.obj nondspR.obj
	$(LINK) -out:gnuchessr.exe mainN.obj bookN.obj genmovesN.obj ataks.obj utilN.obj evalN.obj init.obj searchN.obj dspcomR.obj nondspR.obj $(LIBS)

gnuan.obj: gnuan.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF) -DIGNUAN $(BINBOOK) -c gnuan.c

mainN.obj: main.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) -c main.c
	mv main.obj mainN.obj
mainC.obj: main.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) -DNONDSP -DCHESSTOOL \
		-c main.c
	mv main.obj mainC.obj
mainX.obj: main.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) -DXBOARD  -c main.c
	mv main.obj mainX.obj
mainDR.obj: main.c gnuchess.h version.h ttable.h
	$(CC)  -DDEBUG -DDEBUG4 $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) \
		-c main.c
	mv main.obj mainDR.obj

genmovesN.obj: genmoves.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c genmoves.c
	mv genmoves.obj genmovesN.obj
genmovesC.obj: genmoves.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DCHESSTOOL \
		-c genmoves.c 
	mv genmoves.obj genmovesC.obj
genmovesX.obj: genmoves.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DXBOARD \
		-c genmoves.c
	mv genmoves.obj  genmovesX.obj

eco.obj: eco.c gnuchess.h version.h ataks.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) $(BINECO)  $(PGNECO) -c eco.c 

bookN.obj: book.c gnuchess.h version.h ataks.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) $(PGNECO) $(BINECO) -c book.c 
	mv book.obj bookN.obj
bookG.obj: book.c gnuchess.h version.h ataks.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  $(BINBOOK) $(PGNECO) $(BINECO) -DIGNUAN  -c book.c 
	mv book.obj bookG.obj
bookC.obj: book.c gnuchess.h version.h ataks.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DCHESSTOOL \
	      $(BINBOOK) \
		$(PGNECO) $(BINECO) -c book.c 
	mv book.obj bookC.obj
bookX.obj: book.c gnuchess.h version.h ataks.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DXBOARD  $(BINBOOK) \
		$(PGNECO) $(BINECO) -c book.c
	mv book.obj  bookX.obj

ataks.obj: ataks.h ataks.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c ataks.c

utilN.obj: util.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c util.c
	mv util.obj utilN.obj

utilX.obj: util.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)   \
		 -c util.c
	mv util.obj  utilX.obj

utilC.obj: util.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)   \
		 -c util.c
	mv util.obj  utilC.obj

evalC.obj: eval.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)   -c eval.c
	mv eval.obj evalC.obj

evalX.obj: eval.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)   -c eval.c
	mv eval.obj evalX.obj

evalN.obj: eval.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c eval.c
	mv eval.obj evalN.obj

evalDR.obj: eval.c gnuchess.h version.h ttable.h
	$(CC)  -DDEBUG4 -DDEBUG $(CFLAGS) $(HASH) $(LANGF)  \
		-c eval.c 
	mv eval.obj evalDR.obj
utilDR.obj: util.c gnuchess.h version.h
	$(CC)  -DDEBUG4 -DDEBUG $(CFLAGS) $(HASH) $(LANGF)  \
		-c util.c 
	mv util.obj utilDR.obj

init.obj: init.c gnuchess.h version.h ttable.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c init.c

searchN.obj: search.c gnuchess.h version.h debug512.h debug10.h debug13.h debug16.h debug256.h debug4.h debug40.h debug41.h debug64.h debug8.h ttable.h ttable.c
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c search.c
	mv search.obj searchN.obj
searchG.obj: search.c gnuchess.h version.h debug512.h debug10.h debug13.h debug16.h debug256.h debug4.h debug40.h debug41.h debug64.h debug8.h ttable.h ttable.c
	$(CC) $(CFLAGS) $(HASH) $(LANGF) -DIGNUAN  -c search.c
	mv search.obj searchG.obj
searchC.obj: search.c gnuchess.h version.h debug512.h debug10.h debug13.h debug16.h debug256.h debug4.h debug40.h debug41.h debug64.h debug8.h ttable.h ttable.c
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DCHESSTOOL \
		-c search.c 
	mv search.obj searchC.obj
searchX.obj: search.c gnuchess.h version.h debug512.h debug10.h debug13.h debug16.h debug256.h debug4.h debug40.h debug41.h debug64.h debug8.h ttable.h ttable.c
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DXBOARD \
		-c search.c 
	mv search.obj searchX.obj
searchDR.obj: search.c gnuchess.h version.h debug512.h debug10.h debug13.h debug16.h debug256.h debug4.h debug40.h debug41.h debug64.h debug8.h ttable.h ttable.c
	$(CC)  -DDEBUG4 -DDEBUG $(CFLAGS) $(HASH) $(LANGF)  \
		-c search.c 
	mv search.obj searchDR.obj

uxdsp.obj: uxdsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c uxdsp.c

nuxdsp.obj: nuxdsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c nuxdsp.c

nondspC.obj: nondsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DCHESSTOOL \
		-c nondsp.c 
	mv nondsp.obj nondspC.obj
nondspX.obj: nondsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DXBOARD \
		-c nondsp.c 
	mv nondsp.obj nondspX.obj
nondspR.obj: nondsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP \
		-c nondsp.c 
	mv nondsp.obj nondspR.obj
nondspDR.obj: nondsp.c gnuchess.h version.h
	$(CC)  -DDEBUG4 -DDEBUG $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP \
		 -c nondsp.c 
	mv nondsp.obj nondspDR.obj

dspcomN.obj: dspcom.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -c dspcom.c
	mv dspcom.obj dspcomN.obj
dspcomC.obj: dspcom.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DCHESSTOOL \
		-c dspcom.c 
	mv dspcom.obj dspcomC.obj
dspcomX.obj: dspcom.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP -DXBOARD \
		-c dspcom.c 
	mv dspcom.obj dspcomX.obj
dspcomR.obj: dspcom.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP \
		-c dspcom.c 
	mv dspcom.obj dspcomR.obj
dspcomDR.obj: dspcom.c gnuchess.h version.h
	$(CC)  -DDEBUG -DDEBUG4 $(CFLAGS) $(HASH) $(LANGF)  -DNONDSP \
		-c dspcom.c 
	mv dspcom.obj dspcomDR.obj

postprint.obj: postprint.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) -c postprint.c

binsort.exe: binsort.obj
	$(LINK) -out:binsort.exe binsort.obj $(LIBS)

binsort.obj: binsort.c binsort.h
	$(CC) $(CFLAGS) -c binsort.c

ecosort.exe: ecosort.obj
	$(LINK) -out:ecosort.exe ecosort.obj $(LIBS)

ecosort.obj: ecosort.c gnuchess.h
	$(CC) $(CFLAGS) -c ecosort.c

ecocvt.exe: ecocvt.obj
	$(LINK) -out:ecocvt.exe ecocvt.obj $(LIBS)

ecocvt.obj: ecocvt.c
	$(CC) $(CFLAGS) -c ecocvt.c

gnuchess.data: $(BOOK)
	del input.tmp textbook.tmp gnuchess.data
	echo 3 0 >input.tmp
        echo quit >input.tmp
	gzip -d -c $(BOOK) > textbook.tmp
	gnuchessr < input.tmp -b textbook.tmp -B gnuchess.data $(BOOKOPTS)
	del input.tmp textbook.tmp

# The following doesn't work because binsort isn't ported
gnuchess.eco: ecor.exe binsort.exe ecocvt.exe ecosort.exe
	del gnuchess.eco step0.eco step1.eco step2.eco
	echo 0 0 > step0.eco
	ecor -b ..\book\eco.pgn -B step1.eco < step0.eco
	ecosort 
	ecocvt step2.eco gnuchess.eco
	del step0.eco step1.eco step2.eco

