#
# Makefile for hearts
#

# If you can edit /etc/services, define PORT as 0, else
# define PORT as an unused internet port address (PORT = xxxx)
#
PORT=1030
#
# Dealer port numbers are handed out starting at DIST_PORT.
# Allocate a block of ports starting at DIST_PORT = xxxx.
DIST_PORT=1031

#
# Where hearts_dist had heartsd live
SERVER_BIN=/site/sipb/games/hearts

#
# Where the instructions live
LIB=/mit/sipb/lib

#
# Where the server will attempt to place the file indicating its pid
PID_FILE=-DPID_FILE=\"${SERVER_BIN}/hearts_dist.pid\"

#
# where the executable lives
#
BIN=/mit/sipb/`/bin/athena/machtype`bin

CFLAGS = -O ${PID_FILE}

HCFILES =hearts.c select.c connect.c sockio.c start_dist.c
DCFILES =heartsd.c sockio.c
HDCFILES =hearts_dist.c opensock.c sockio.c

HOFILES =hearts.o select.o connect.o sockio.o start_dist.o
DOFILES =heartsd.o sockio.o
HDOFILES =hearts_dist.o opensock.o sockio.o

all:	hearts heartsd hearts_dist

install: 	$(LIB)/hearts.instr $(BIN)/hearts

install-server: $(SERVER_BIN)/heartsd $(SERVER_BIN)/hearts_dist 

$(SERVER_BIN)/heartsd: heartsd
	cp heartsd $(LIB)

$(SERVER_BIN)/hearts_dist: hearts_dist
	cp hearts_dist $(LIB)

$(LIB)/hearts.instr: hearts.instr
	cp hearts.instr $(LIB)

$(BIN)/hearts: hearts
	cp hearts $(BIN)

hearts:	$(HOFILES)
	cc $(CFLAGS) -o $@ $(HOFILES) -lcurses -ltermlib

heartsd: $(DOFILES)
	cc $(CFLAGS) -o $@ $(DOFILES)

hearts_dist: $(HDOFILES)
	cc $(CFLAGS) -o $@ $(HDOFILES)

local.h: .local.h

.local.h: Makefile local.proto
	sed -e 's;HEARTSLIB;$(LIB);' \
	    -e 's;SERVER_BIN;$(SERVER_BIN);' \
	    -e 's;DIST_PORTNUM;$(DIST_PORT);' \
	    -e 's;PORTNUM;$(PORT);' \
	 	local.proto > .local.h
	-if cmp -s .local.h local.h; then\
 		:;\
 	else\
 		cp .local.h local.h;\
 	fi

always:

hearts.o: misc.h defs.h local.h
heartsd.o: misc.h defs.h local.h
hearts_dist.o: misc.h defs.h local.h
select.o: misc.h defs.h
sockio.o: defs.h
start_dist.o: local.h
connect.o: defs.h local.h
opensock.o: defs.h local.h

clean:	
	rm -f $(HOFILES) $(DOFILES) $(HDOFILES) hearts hearts_dist local.h .local.h

lint:	linthearts lintheartsd linthearts_dist

linthearts:
	lint $(DEFS) $(HCFILES)

lintheartsd:
	lint $(DEFS) $(DCFILES)

linthearts_dist:
	lint $(DEFS) $(HDCFILES)

