DESTDIR = /usr/local/games/
XTREKDIR = /usr/local/games/lib/netrek/
CFLAGS = -O -s -DHAS_GALAXY
LIBS = -lm 

EXECS =	players planets message watchmes resetplanets xtkill scores \
	newscores trimscores showgalaxy nuke makescores mess pl3 setgalaxy \
	gstat

all: $(EXECS)

clean:
	-rm -f *.o
clobber: clean
	-rm -f $(EXECS)

watchmes: watchmes.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) watchmes.c $(LIBS)

resetplanets: resetplanets.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) resetplanets.c $(LIBS) 

xtkill: xtkill.c struct.h
	$(CC) -o $@ $(CFLAGS) xtkill.c $(LIBS)

players: players.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) players.c $(LIBS)
#	cp players $(DESTDIR)/trekplayers
#	chmod 4711 $(DESTDIR)/trekplayers

planets: planets.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) planets.c $(LIBS)

message: message.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) message.c $(LIBS)

mess: mess.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) mess.c $(LIBS)

pl3: pl3.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) pl3.c $(LIBS)

setgalaxy: setgalaxy.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) setgalaxy.c $(LIBS) -lbsd

gstat: stat.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) stat.c $(LIBS)

scores: scores.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) scores.c $(LIBS)
#	cp scores $(DESTDIR)/trekscores
#	chmod 4711 $(DESTDIR)/trekscores

trimscores: trimscores.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) trimscores.c $(LIBS)

newscores: newscores.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) newscores.c $(LIBS)

showgalaxy: showgalaxy.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) showgalaxy.c $(LIBS) -lcurses -ltermcap -lbsd -lsocket

nuke:	nuke.c struct.h defs.h
	$(CC) -o $@ $(CFLAGS) nuke.c $(LIBS)
makescores: makescores.sh
	cp makescores.sh makescores

install:
	mv scores $(DESTDIR)/trekscores
	chown fadden $(DESTDIR)/trekscores
	chmod 4711 $(DESTDIR)/trekscores
	mv players $(DESTDIR)/trekplayers
	chown fadden $(DESTDIR)/trekscores
	chmod 4711 $(DESTDIR)/trekplayers
	-ln -s $(DESTDIR)/trekscores $(XTREKDIR)/scores
	-ln -s $(DESTDIR)/trekplayers $(XTREKDIR)/players
	mv makescores $(XTREKDIR)
	chown fadden $(XTREKDIR)/makescores
	chmod 700 $(XTREKDIR)/makescores
	mv message watchmes planets resetplanets xtkill newscores trimscores \
		showgalaxy nuke $(XTREKDIR)
	chown fadden $(XTREKDIR)/message \
		     $(XTREKDIR)/watchmes \
		     $(XTREKDIR)/resetplanets \
		     $(XTREKDIR)/xtkill \
		     $(XTREKDIR)/newscores \
		     $(XTREKDIR)/planets \
		     $(XTREKDIR)/trimscores \
		     $(XTREKDIR)/showgalaxy \
		     $(XTREKDIR)/nuke
	chmod 700 $(XTREKDIR)/message \
		  $(XTREKDIR)/watchmes \
		  $(XTREKDIR)/resetplanets \
		  $(XTREKDIR)/xtkill \
		  $(XTREKDIR)/newscores \
		  $(XTREKDIR)/planets \
		  $(XTREKDIR)/trimscores \
		  $(XTREKDIR)/showgalaxy \
		  $(XTREKDIR)/nuke
