#
# Makefile for GNU Chess
#

#
# gnuchessa is Amiga curses
# gnuchess  is a curses-based chess.
# gnuchessn is a fancy-display-curses-based chess.
# gnuchessr is a plain dumb-terminal chess (but with full variation output)
# gnuchessc is suitable for chesstool use (mimics /usr/games/chess output)
# gnuchessx is the xchess based chess.
#

# The version number of this GNU and Xboard release
VERS=	4.0
XVERS = 2.0

# Relevant file areas.
DIST=	../README ../README.lang ../doc ../misc ../src ../test

# Distribution directory
DISTDIR=gnlib:

# Programs being distributed
#PROGS=gnuchess-$(VERS) xboard-$(XVERS)
PROGS=gnuchess-$(VERS)

# Change these to something less transitory, like /usr/games, and then
# compile. Ask your system admin / unix guru to put gnuchess.{hash,lang,book}
# in $(LIBDIR).
# Where the binaries live.
BINDIR=

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

# Display routines.
#LCURSES=-lcurses -ltermcap
LCURSES=-ltermcap

#compile options for gnuchess
# -DAG[0-4]  selects a set of values for SpaceBonus tables
# -DQUIETBACKGROUND don't print post information in background ( easy OFF)
# -DNOMEMSET if your machine does not support memset
# -DNOMATERIAL don't call it a draw when no pawns and both sides < rook
# -DNODYNALPHA don't dynamically adjust alpha
# -DHISTORY use history killer hueristic 
# -DKILLT use killt killer hueristic 
# -DNOSCORESPACE don't use Scorespace heuristic
# -DOLDXBOARD don't generate underpromote moves
# -DGNU3 don't generate underpromote moves
# -DLONG64 if you have 64bit longs
# -DSYSV   if you are using SYSV
# 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
# -DDEBUG40 include extra values of variables for debugging  in game list
# the rest of the debug options are tied to the debuglevel command
# -DDEBUG -DDEBUG4 set 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
#	      256 print search tree as it is generated
# Added by MWS:
# -DALWAYSLIST	always list game on exit
# -DRANDOMIZE	random-mode (dither) always set for new game
# -DCOORDSOFF	if board coords are initially off

OPT=-v -dAG4 -dRANDOMIZE -d0
OPT2=-j87# -O
# The hashfile is a record of positions seen. It is used by
# GNU Chess to avoid making the same mistakes, a form of learning.
#HASH=	-dHASHFILE="$(LIBDIR)gnuchess.hash"
HASH=

# The "book" is a record of the first few moves, for playing good
# moves easily and quickly, saving time, and irritating the human
# opponent.
#BOOK=	-dBOOK="$(LIBDIR)gnuchess.book"
BOOK=
#BINBOOK = -dBINBOOK="$(LIBDIR)/gnuchess.book.data"

# The language file describes capabilities of the program. Perhaps
# it is useful for non-English speaking countries and customizing
# for their convenience and chess happiness.
#LANG= -dLANGFILE="$(LIBDIR)gnuchess.lang"
LANG=

# The compiler used for compiling this software.
# Use this for a plain C compiler 
#CC= cc $(OPT)
# Use this for DEC's ANSI C compiler on Ultrix
#CC= c89 $(OPT)
# Use this if you are lucky enough to have GNU CC.
CC=	lc $(OPT)
#CC=	/contrib/system/bin/gcc -W $(OPT)

# Miscellaneous CFLAGS. Uncomment the one you need and comment 
# the other.
#CFLAGS= -p -dinline=""	 -traditional-cpp
#CFLAGS= -O4 -Qpath .  # SunOS cc using unprotoize
#CFLAGS= -O4 # Sun acc
#CFLAGS= -g  # debug
#CFLAGS= -O2
#CFLAGS= +O3 -Aa -d_HPUX_SOURCE -dSYSV # HPUX cc 
#CFLAGS= -O   -finline-functions -fstrength-reduce -d__mips -d__LANGUAGE_C # gnu cc 1.40 on DS5000
#CFLAGS= -O   -finline-functions -fstrength-reduce  # gnu cc 1.40 on others
#CFLAGS= -O2 -funroll-loops -d__mips -d__LANGUAGE_C # gnu cc 2.00 on DS5000
#CFLAGS= -O2 -funroll-loops -traditional-cpp  # gnu cc  2.00 on SunOS
#CFLAGS= -O2 -funroll-loops  # gnu cc  2.00 on others
CFLAGS=-Hdefines.sym -j88 -cs
#CURSES=curses.lib
CURSES=curse.o

AMIOBJS=amiga/amiterm.o amiga/beep.o amiga/amidsp.o amiga/display.o amiga/draw.o \
	amiga/pieces.o amiga/pointer.o amiga/requester.o

ami: defines.sym gnuchessa

defines.sym: defines.c gnuchess.h
	$(CC) -ph -odefines.sym defines.c

all : gnuchess gnuchessr gnuchessn gnuchessx gnuchessc postprint gnuan game checkbook checkgame

gnuchessa: mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o $(AMIOBJS) tmp.lnk
	blink with tmp.lnk

tmp.lnk: makefile
	 echo "Remaking link file..."
	@echo >tmp.lnk "FROM lib:c.o"
	@echo >>tmp.lnk "mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o"
	@echo >>tmp.lnk $(AMIOBJS)
	@echo >>tmp.lnk "TO gnuchessa"
	@echo >>tmp.lnk "LIBRARY "
	@echo >>tmp.lnk "lib:umain2.o lib:reqtools.lib lib:lc.lib lib:amiga.lib"
	@echo >>tmp.lnk "SC ND VERBOSE"

gnuchess: mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o uxdsp.o
	blink from lib:c.o  mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o uxdsp.o\
	to gnuchess lib curses32.lib lib:lcnb.lib lib:amiga.lib sc nd

gnuchessn: mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o nuxdsp.o
	blink from lib:c.o mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o dspcomN.o nuxdsp.o\
	to gnuchessn lib $(CURSES) lib:umain2.o lib:lc.lib lib:amiga.lib sc nd
	
gnuan: mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o gnuan.o
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK) -o gnuan mainN.o bookN.o genmovesN.o ataks.o util.o evalN.o init.o searchN.o gnuan.o

game: game.c gnuchess.h
	$(CC) $(CFLAGS) -o game game.c
	
postprint: postprint.o
	$(CC) $(CFLAGS) -o postprint postprint.o
	
checkbook: checkbook.o
	$(CC) $(CFLAGS) -o checkbook checkbook.o
	
checkgame: checkgame.o
	$(CC) $(CFLAGS) -o checkgame checkgame.o

gnuan.o: gnuan.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK) gnuan.c

mainN.o: main.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK) main.c
	-delete mainN.o
	rename main.o mainN.o

genmovesN.o: genmoves.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  genmoves.c
	-delete genmovesN.o
	rename genmoves.o genmovesN.o

bookN.o: book.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK) $(BINBOOK)  book.c 
	-delete bookN.o
	rename book.o bookN.o

ataks.o: ataks.h ataks.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  ataks.c

util.o: util.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  util.c

evalN.o: eval.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  eval.c
	-delete evalN.o
	rename eval.o evalN.o

init.o: init.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  init.c

searchN.o: search.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  search.c
	-delete searchN.o
	rename search.o searchN.o

nuxdsp.o: nuxdsp.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(OPT2) $(HASH) $(LANG) $(BOOK)  nuxdsp.c

dspcomN.o: dspcom.c gnuchess.h version.h
	$(CC) $(CFLAGS) $(HASH) $(LANG) $(BOOK)  dspcom.c
	-delete dspcomN.o
	rename dspcom.o dspcomN.o

postprint.o: postprint.c gnuchess.h version.h
	$(CC) $(CFLAGS)  postprint.c

AMIFLAGS=$(CFLAGS) -Hinclude:intui.sym

amiga/amiterm.o: amiga/amiterm.c
	$(CC) $(AMIFLAGS) amiga/amiterm.c

amiga/beep.o: amiga/beep.c
	$(CC) $(AMIFLAGS) amiga/beep.c

amiga/amidsp.o: amiga/amidsp.c
	$(CC) $(AMIFLAGS) -j87 $(HASH) $(LANG) $(BOOK) amiga/amidsp.c

amiga/display.o: amiga/display.c
	$(CC) $(AMIFLAGS) amiga/display.c

amiga/draw.o: amiga/draw.c amiga/draw.h
	$(CC) $(AMIFLAGS) amiga/draw.c

amiga/pieces.o: amiga/pieces.c
	$(CC) $(AMIFLAGS) amiga/pieces.c
