#
# Makefile for GNU othello
#
# Inge Wallin			ingwa@isy.liu.se
#

#
# Change the following variables to suit the situation at your own site.
#
# BINDIR is the directory where the executable will be placed on 
# `make install'.  MANDIR is the manual directory and MANEXT is the 
# extension the manual file name will have in MANDIR.
#

BINDIR = /usr/local/gnu/bin
MANDIR = /usr/local/man/man6
MANEXT = 6


# Choose a C compiler and the compilation flags.
CC = gcc
#CFLAGS = -O3 -fomit-frame-pointer -mpentiumpro
CFLAGS = -O -g -Wall
#CFLAGS = -g -Wall

#CC = cc
#CFLAGS = -O
#CFLAGS = -g


# Choose a C compiler to link with. Sometimes you want to use one
# compiler to compile with since it produces faster code and another
# to link with since the first one doesn't produce executables with
# shared libraries. This is the case with gcc and cc on the SUN.
LINKCC = gcc
#LINKCC = gcc -pg


# *************************************************************
# ********   DON'T CHANGE ANYTHING BELOW THIS LINE     ********
# *************************************************************

VERSION = 1.3
DISTDIR = iwothello-$(VERSION)

TTYOBJS = tty.o
TTYLIBS = 

XOBJS = x11.o textwindow.o
XLIBS = -lXaw -lXmu -lXt -lX11

SVOBJS = sunview.o textwindow.o
SVLIBS = -lsuntool -lsunwindow -lpixrect

CLOBJS = remoteterm.o remote_clnt.o remote_xdr.o
CLLIBS =

CUROBJS = curses.o textwindow.o
CURLIBS = -lcurses -ltermcap
#CURLIBS = -lcurses -ltermlib

# IO for the server
SERVOBJS = $(TTYOBJS)
SERVLIBS = $(TTYLIBS)

SRCS =	main.c sqlist.c globals.c search.c lowlevel.c \
	curses.c tty.c sunview.c textwindow.c
SRC2 =	server.c remote.x showedgeval.c testsqlist.c remoteterm.c \
	oldothello.c edgeval.c edgeval.h dist_makefile Makefile
HDRS =	sqlist.h globals.h othello.h textwindow.h io. hversion.h
ICONS = blackpiece.icon whitepiece.icon nopiece.icon othellotool.icon
SRC3 =	README TODO PORTING othello.man $(ICONS)

GAMEOBJS = main.o sqlist.o globals.o search.o lowlevel.o



info:
	@echo
	@echo 'You can compile othello for the following interfaces using'
	@echo 'the following commands:'
	@echo
	@echo 'make tty       - Scrolling interface for a tty'
	@echo
	@echo 'make curses    - Interface for curses    (only for demo purposes)'
	@echo 'make sunview   - Interface for sunview   (not working right now)'
	@echo 'make x11       - Interface for X Windows (not working right now)'
	@echo 'The outfile will always be named othello.'
	@echo

x11: $(GAMEOBJS) $(XOBJS)
	$(LINKCC) -o xothello $(GAMEOBJS) $(XOBJS) $(LIBS) $(XLIBS)
	rm -f othello
	ln xothello othello

sunview: $(GAMEOBJS) $(SVOBJS)
	$(LINKCC) -o svothello $(GAMEOBJS) $(SVOBJS) $(LIBS) $(SVLIBS)
	rm -f othello
	ln svothello othello

tty:	$(GAMEOBJS) $(TTYOBJS)
	$(LINKCC) -o ttyothello $(GAMEOBJS) $(TTYOBJS) $(LIBS) $(TTYLIBS)
	rm -f othello
	ln ttyothello othello

curses:	$(GAMEOBJS) $(CUROBJS)
	$(LINKCC) -o curothello $(GAMEOBJS) $(CUROBJS) $(LIBS) $(CURLIBS)
	rm -f othello
	ln curothello othello

client:	$(GAMEOBJS) $(CLOBJS)
	$(LINKCC) -o othello $(GAMEOBJS) $(CLOBJS) $(LIBS) $(CLLIBS)


testsqlist: testsqlist.o sqlist.o
	$(CC) $(CFLAGS) -o testsqlist testsqlist.o sqlist.o

stats: stats.o sqlist.o
	$(CC) $(CFLAGS) -o stats \
		stats.o sqlist.o globals.o search.o lowlevel.o

board: board.o sqlist.o
	$(CC) $(CFLAGS) -o board \
		board.o sqlist.o

showedgeval: showedgeval.o edgeval.o
	$(CC) $(CFLAGS) -o showedgeval showedgeval.o edgeval.o


SERVEROBJS = remote_svc.o remote_xdr.o server.o sqlist.o lowlevel.o \
	globals.o
server:	$(SERVEROBJS) $(SERVOBJS)
	$(LINKCC) -o server $(SERVEROBJS) $(SERVLIBS)


clean:
	rm -f  *.o *~ core othello xothello svothello ttyothello curothello
	rm -f stats board
	rm -f showedgeval server
	rm -f  remote_svc.c remote_clnt.c remote_xdr.c remote.h
	rm -rf $(DISTDIR)

install:	othello othello.man
	cp othello $(BINDIR)
	cp othello.man $(MANDIR)/othello.$(MANEXT)


tags:
	etags $(SRCS) $(HDRS)

lint:
	lint $(SRCS)

distribution:
	-mkdir $(DISTDIR)
	rm -rf $(DISTDIR)/*
	cp $(SRCS) $(HDRS) $(SRC3) $(DISTDIR)
	cp dist_makefile $(DISTDIR)/Makefile
	tar cvf $(DISTDIR).tar $(DISTDIR)
	compress $(DISTDIR).tar

shar:
	shar $(SRCS) $(HDRS) $(SRC2) $(SRC3) > othello.shar

wc:
	wc $(SRCS) $(HDRS)


main.o:		othello.h sqlist.h globals.h io.h version.h
globals.o:	othello.h sqlist.h
search.o:	othello.h globals.h
lowlevel.o:	othello.h sqlist.h globals.h io.h
sqlist.o:	sqlist.h
tty.o:		othello.h sqlist.h globals.h io.h version.h
sunview.o:	textwindow.h othello.h globals.h io.h $(ICONS) version.h
textwindow.o:	textwindow.h
remoteterm.o:	othello.h globals.h io.h remote.h
curses.o:	textwindow.h othello.h globals.h io.h version.h
testsqlist.o:	sqlist.h
showedgeval.o:	othello.h edgeval.h
server.o:	remote.h othello.h sqlist.h globals.h io.h
edgeval.o:	othello.h edgeval.h

stats.o:	othello.h sqlist.h globals.h
board.o:	othello.h sqlist.h globals.h


remote_svc.c remote_clnt.c remote_xdr.c remote.h: remote.x
	rpcgen remote.x
