# NETREK II -- Paradise
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any NON-COMMERCIAL purpose (following the terms of
# the GNU General Public License (read the file 'COPYING')) and without 
# fee is hereby granted, provided that this copyright notice appear in all 
# copies.  No representations are made about the suitability of this 
# software for any purpose.  This software is provided "as is" without 
# express or implied warranty.
# 
#    Xtrek Copyright 1986                            Chris Guthrie
#    Netrek (Xtrek II) Copyright 1989                Kevin P. Smith
#                                                    Scott Silvey
#    Paradise (Netrek II) Copyright 1993             Larry Denys
#                                                    Kurt Olsen
#                                                    Brandon Gillespie
#                                                    Rob Forsman
#
#    Comprehensive Credits available in the file docs/CREDITS
#
# Programmers: Modify the file 'Makefile.in' not the Makefile directly.
#

MAKE = make
INSTMODE = 700

SRVDIR = .
BINDIR = ../bin
ETCDIR = ../etc
RSADIR = ../rsa

#@@CCOPTIONS@
#@@CDEBUGFLAGS@
#@@CC@

### An override
# GCCWARNINGS = 
# GCCOPTWARNINGS= -O -Wuninitialized -Wunused
# GCCWARNINGS = ${GCCOPTWARNINGS} -Wreturn-type -Wswitch -Wtrigraphs \
#	-Wformat -Wchar-subscripts -Wparentheses
# CC = gcc ${GCCWARNINGS}

# Use this for the KSR1 supercomputer
# CC = cc -port_def_long -port_lowaddrs

####################
# RSA authorization stuff

#@@RSA@
#@@AUTHOBJS@

#####################

#@@LIBS@

#####################
# GNU Zip libs
GZLIBPATH = -L/usr/local/lib
GZLIB = -lgz
GZLIBH = -I/usr/local/include

####################
#accumulation of all C flags.

CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(RSA) $(GZLIBH)

##############################################################################

COMMON = data.o shmem.o plutil.o path.o grid.o cutil.o sintab.o

ME_COMMON = util.o

TOOL_COMMON = shmem.o path.o data.o

NTSERV_OBJS = ${COMMON} cluecheck.o message.o death.o detonate.o \
	enter.o fatudp.o findslot.o gameconf.o getentry.o getname.o \
        getship.o input.o interface.o main.o missile.o orbit.o packets.o \
	parsexbm.o phaser.o ping.o plasma.o redraw.o ${AUTHOBJS} socket.o \
	sockio.o smessage.o timecheck.o torp.o ${ME_COMMON} warning.o \
	imath.o feature.o

DAEMON_OBJS = daemonII.o dutil.o ${COMMON} conquer.o shipvals.o structdesc.o \
	sysdefaults.o weapons.o planets.o pl_gen0.o pl_gen1.o \
	pl_gen2.o pl_gen3.o pl_gen4.o pl_gen5.o pl_gen6.o pl_gen7.o player.o stats.o \
	misc.o tourny.o imath.o terrain.o

ROBOT_OBJS = ${COMMON} detonate.o enter.o getship.o interface.o orbit.o \
	phaser.o robotII.o rmove.o torp.o ${ME_COMMON} imath.o

SNAKE_OBJS = data.o path.o shmem.o cutil.o snake.o sintab.o snakemove.o \
	${ME_COMMON} imath.o

LISTEN_OBJS = data.o path.o listen.o

TOOL_MES_OBJS = tool-mes.o tool-util.o ${TOOL_COMMON}

TOOL_XTK_OBJS = tool-xtk.o tool-util.o ${TOOL_COMMON} getship.o # grid.o \
#	plutil.o

TOOL_WM_OBJS = tool-wm.o tool-util.o ${TOOL_COMMON}

TOOL_RESET_OBJS = tool-reset.o ${TOOL_COMMON}

TOOL_PL_OBJS = tool-pl.o tool-util.o ${TOOL_COMMON}

TOOL_PROMO_OBJS = tool-promo.o data.o

TOOL_HR_OBJS = tool-hr.o ${TOOL_COMMON}

TOOL_HS_OBJS = tool-hs.o ${TOOL_COMMON}

TOOL_HERALDRY_OBJS = tool-heraldry.o data.o

TOOL_DS_OBJS = tool-ds.o shmem.o path.o structdesc.o data.o

TOOL_TRIM_OBJS = tool-trim.o ${TOOL_COMMON}

R_FILES = data.c death.c detonate.c enter.c findslot.c getentry.c getname.c \
	getship.c input.c interface.c main.c orbit.c phaser.c plasma.c \
	redraw.c reserved.c sintab.c socket.c smessage.c timecheck.c torp.c \
	util.c path.c

SRC = $(R_FILES) data.h defs.h planets.h struct.h packets.h

DAEMON_SRCS=`echo ${DAEMON_OBJS} | sed -e 's/\.o/.c/g'`

NTSERV_SRCS=`echo ${NTSERV_OBJS} | sed -e 's/\.o/.c/g'`

ROBOT_SRCS=`echo ${ROBOT_OBJS} | sed -e 's/\.o/.c/g'`

##############################################################################

SERVER = ntserv daemonII listen

ROBOTS = robotII snake

TOOLS = mes wm hr hs
OTHERTOOLS = reset pl promo ds xtk heraldry trim

default:
	@echo "** Use 'make rules' for a list of make rules **"
	${MAKE} server

rules:
	@echo "*** Use any of the following ***"; \
        echo "  General:"; \
        echo "    server, robots, tools, alltools, makefile, install,"; \
        echo "    install-tools, rsa, rsa-support, clean, spotless."; \
        echo "  Specific:"; \
        echo "    $(SERVER) $(ROBOTS)"; \
        echo "    $(TOOLS) $(OTHERTOOLS)"

makefile:
	@cd ..;	setup -p

patchable: spotless
	@echo "all:" > Makefile; \
        echo "	@echo \"\"; \\" >> Makefile; \
        echo "echo \"** Run the setup script first **\"; \\" >> Makefile; \
        echo "echo \"\"" >> Makefile; \
        echo "server: all" >> Makefile; \
        echo "install: all" >> Makefile

server: $(SERVER) $(ROBOTS)

robots: $(ROBOTS)

tools: $(TOOLS)

alltools: $(TOOLS) ${OTHERTOOLS}

rsa:
	cd $(RSADIR); make; cd $(SRVDIR)

rsa-support:
	-ln -s $(RSADIR)/rsa-server.c
	-ln -s $(RSADIR)/rsa_util.c
	-ln -s $(RSADIR)/rsa_utilmp.c
	-ln -s $(RSADIR)/reserved.c

ntserv: $(NTSERV_OBJS)
	${CC} $(CFLAGS) $(GZLIBPATH) -o ntserv $(NTSERV_OBJS) $(LIBS) $(GZLIB)
	-chmod ${INSTMODE} ntserv

daemonII: $(DAEMON_OBJS)
	${CC} $(CFLAGS) $(GZLIBPATH) -o daemonII $(DAEMON_OBJS) ${LIBS} $(GZLIB)
	-chmod ${INSTMODE} daemonII

robotII: $(ROBOT_OBJS)
	${CC} $(CFLAGS) -o robotII $(ROBOT_OBJS) $(LIBS)
	-chmod ${INSTMODE} robotII

listen: $(LISTEN_OBJS)
	${CC} ${CFLAGS} $(GZLIBPATH) -o $@ ${LISTEN_OBJS} $(LIBS) $(GZLIB)

snake:   $(SNAKE_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ $(SNAKE_OBJS) $(LIBS)
	-chmod ${INSTMODE} snake

mes:	$(TOOL_MES_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_MES_OBJS} $(LIBS)

wm:	$(TOOL_WM_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_WM_OBJS} $(LIBS)

xtk:	$(TOOL_XTK_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_XTK_OBJS} $(LIBS)

reset:	$(TOOL_RESET_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_RESET_OBJS} $(LIBS)

pl:	$(TOOL_PL_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_PL_OBJS} $(LIBS)

promo:	$(TOOL_PROMO_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_PROMO_OBJS} $(LIBS)

hr:	$(TOOL_HR_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_HR_OBJS} $(LIBS)

hs:	$(TOOL_HS_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_HS_OBJS} $(LIBS)

heraldry:	$(TOOL_HERALDRY_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_HERALDRY_OBJS} $(LIBS)

ds:	$(TOOL_DS_OBJS)
	/bin/rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_DS_OBJS} $(LIBS)

trim: ${TOOL_TRIM_OBJS}
	rm -f $@
	${CC} $(CFLAGS) -o $@ ${TOOL_TRIM_OBJS} $(LIBS)

install: $(BINDIR)/daemonII $(BINDIR)/ntserv $(BINDIR)/listen \
	$(BINDIR)/robotII $(BINDIR)/snake

install-tools: $(BINDIR)/mes $(BINDIR)/wm $(BINDIR)/reset $(BINDIR)/pl \
	$(BINDIR)/promo $(BINDIR)/hr $(BINDIR)/hs $(BINDIR)/ds # $(BINDIR)/xtk

$(BINDIR)/ntserv: ntserv
	-mv $@ $@.old
	cp ntserv $@
	chmod ${INSTMODE} $@

$(BINDIR)/daemonII: daemonII
	-mv $@ $@.old
	rm -f $(ETCDIR)/planets
	touch $(ETCDIR)/planets
	chmod 600 $(ETCDIR)/planets
	cp daemonII $@
	chmod ${INSTMODE} $@

$(BINDIR)/robotII: robotII
	-mv $@ $@.old
	cp robotII $@
	chmod ${INSTMODE} $@

$(BINDIR)/listen: listen
	-mv $@ $@.old
	cp listen $@
	chmod ${INSTMODE} $@

$(BINDIR)/snake: snake
	-mv $@ $@.old
	cp snake $@
	chmod ${INSTMODE} $@

$(BINDIR)/mes: mes
	-mv $@ $@.old
	cp mes $@
	chmod ${INSTMODE} $@

$(BINDIR)/wm: wm
	-mv $@ $@.old
	cp wm $@
	chmod ${INSTMODE} $@

$(BINDIR)/xtk: xtk
	-mv $@ $@.old
	cp xtk $@
	chmod ${INSTMODE} $@

$(BINDIR)/reset: reset
	-mv $@ $@.old
	cp reset $@
	chmod ${INSTMODE} $@

$(BINDIR)/pl: pl
	-mv $@ $@.old
	cp pl $@
	chmod ${INSTMODE} $@

$(BINDIR)/promo: promo
	-mv $@ $@.old
	cp promo $@
	chmod ${INSTMODE} $@

$(BINDIR)/hr: hr
	-mv $@ $@.old
	cp hr $@
	chmod ${INSTMODE} $@

$(BINDIR)/hs: hs
	-mv $@ $@.old
	cp hs $@
	chmod ${INSTMODE} $@

$(BINDIR)/ds: ds
	-mv $@ $@.old
	cp ds $@
	chmod ${INSTMODE} $@

#
#

lint-daemon:
	lint ${DAEMON_SRCS} 

#
#

protoize-daemon:
	protoize -c "${CFLAGS}" -gN ${DAEMON_SRCS}

protoize-ntserv:
	protoize -c "${CFLAGS}" -gN ${NTSERV_SRCS}

protoize-robotII:
	protoize -c "${CFLAGS}" -gN ${ROBOT_SRCS}

unprotoize-daemon:
	unprotoize -c "${CFLAGS}" -N ${DAEMON_SRCS}

unprotoize-ntserv:
	unprotoize -c "${CFLAGS}" -N ${NTSERV_SRCS}

unprotoize-robotII:
	unprotoize -c "${CFLAGS}" -N ${ROBOT_SRCS}

#
#

clean:
	rm -f *~ *.BAK *.orig *.rej core
	rm -f $(SERVER) $(ROBOTS) $(TOOLS) $(OTHERTOOLS)

spotless: clean
	rm -f *.o

#############################################################################
cluecheck.o : cluecheck.c config.h data.h defs.h struct.h shmem.h 
cluecheckdriver.o : cluecheckdriver.c 
conquer.o : conquer.c config.h defs.h struct.h data.h daemonII.h misc.h shmem.h \
  path.h 
message.o : message.c config.h defs.h data.h struct.h shmem.h 
cutil.o : cutil.c config.h data.h defs.h 
daemonII.o : daemonII.c config.h defs.h struct.h data.h planets.h conquer.h \
  daemonII.h getship.h weapons.h player.h misc.h shmem.h path.h 
data.o : data.c config.h defs.h struct.h data.h 
death.o : death.c config.h defs.h struct.h data.h shmem.h 
detonate.o : detonate.c config.h defs.h struct.h data.h shmem.h 
dutil.o : dutil.c config.h defs.h struct.h data.h daemonII.h shmem.h 
enter.o : enter.c config.h defs.h struct.h data.h shmem.h grid.h 
fatudp.o : fatudp.c config.h defs.h data.h packets.h shmem.h struct.h 
findslot.o : findslot.c config.h defs.h struct.h data.h packets.h shmem.h 
gameconf.o : gameconf.c config.h defs.h gppackets.h packets.h shmem.h struct.h \
  data.h 
getentry.o : getentry.c config.h defs.h struct.h data.h packets.h shmem.h 
getname.o : getname.c config.h defs.h struct.h data.h packets.h path.h shmem.h 
getship.o : getship.c config.h defs.h struct.h data.h shmem.h 
getstats.o : getstats.c config.h 
grid.o : grid.c config.h struct.h defs.h shmem.h 
input.o : input.c config.h defs.h struct.h data.h shmem.h 
interface.o : interface.c config.h defs.h struct.h data.h shmem.h 
listen.o : listen.c path.h 
main.o : main.c config.h defs.h struct.h data.h packets.h shmem.h path.h 
misc.o : misc.c config.h defs.h misc.h struct.h data.h daemonII.h planets.h \
  shmem.h 
missile.o : missile.c config.h defs.h struct.h data.h shmem.h grid.h 
orbit.o : orbit.c config.h defs.h struct.h data.h shmem.h 
packets.o : packets.c config.h defs.h packets.h gppackets.h wtext.h 
parsexbm.o : parsexbm.c config.h 
path.o : path.c config.h 
phaser.o : phaser.c config.h defs.h struct.h data.h weapons.h shmem.h 
ping.o : ping.c config.h defs.h struct.h data.h packets.h shmem.h 
pl_gen0.o : pl_gen0.c config.h defs.h struct.h shmem.h planets.h 
pl_gen1.o : pl_gen1.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen2.o : pl_gen2.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen3.o : pl_gen3.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen4.o : pl_gen4.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen5.o : pl_gen5.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen6.o : pl_gen6.c config.h defs.h struct.h data.h shmem.h planets.h 
pl_gen7.o : pl_gen6.c config.h defs.h struct.h data.h shmem.h planets.h
planets.o : planets.c config.h defs.h struct.h data.h daemonII.h planets.h misc.h \
  conquer.h player.h grid.h shmem.h 
plasma.o : plasma.c config.h defs.h struct.h data.h shmem.h 
player.o : player.c config.h defs.h struct.h data.h daemonII.h player.h shmem.h \
  conquer.h 
plutil.o : plutil.c config.h plutil.h data.h defs.h shmem.h struct.h 
redraw.o : redraw.c config.h defs.h struct.h data.h packets.h shmem.h 
reserved.o : reserved.c config.h defs.h packets.h 
resetpassword.o : resetpassword.c struct.h defs.h 
rmove.o : rmove.c config.h defs.h struct.h data.h weapons.h shmem.h 
robotII.o : robotII.c config.h defs.h struct.h data.h shmem.h 
rsa-server.o : rsa-server.c defs.h struct.h data.h packets.h 
rsa_utilmp.o : rsa_utilmp.c 
shipvals.o : shipvals.c config.h defs.h struct.h data.h shmem.h 
shmem.o : shmem.c config.h shmem.h struct.h defs.h path.h data.h shmemP.h 
sintab.o : sintab.c 
smessage.o : smessage.c config.h defs.h struct.h data.h shmem.h 
snake.o : snake.c config.h defs.h struct.h data.h shmem.h 
snakemove.o : snakemove.c config.h defs.h struct.h data.h planets.h shmem.h 
socket.o : socket.c config.h defs.h struct.h data.h packets.h shmem.h path.h \
  gppackets.h 
sockio.o : sockio.c config.h data.h defs.h packets.h shmem.h struct.h 
stats.o : stats.c config.h defs.h struct.h shmem.h 
structdesc.o : structdesc.c config.h structdesc.h struct.h defs.h 
sysdefaults.o : sysdefaults.c config.h defs.h struct.h data.h getship.h shmem.h \
  path.h structdesc.h 
terrain.o : terrain.c terrain.h struct.h shmem.h
timecheck.o : timecheck.c config.h path.h 
tool-ds.o : tool-ds.c config.h shmem.h struct.h defs.h structdesc.h 
tool-reset.o : tool-reset.c config.h defs.h shmem.h struct.h getship.h 
tool-heraldry.o : tool-heraldry.c config.h defs.h struct.h data.h 
tool-hs.o : tool-hs.c config.h struct.h defs.h 
tool-hr.o : tool-hr.c config.h defs.h struct.h path.c path.h 
tool-mes.o : tool-mes.c config.h defs.h data.h shmem.h struct.h 
tool-pl.o : tool-pl.c config.h data.h defs.h shmem.h struct.h tool-util.h 
tool-promo.o : tool-promo.c config.h struct.h defs.h data.h 
tool-trim.o : tool-trim.c config.h defs.h struct.h 
tool-util.o : tool-util.c config.h tool-util.h defs.h 
tool-wm.o : tool-wm.c config.h defs.h struct.h shmem.h 
tool-xtk.o : tool-xtk.c config.h defs.h shmem.h struct.h getship.h 
torp.o : torp.c config.h defs.h struct.h data.h shmem.h 
tourny.o : tourny.c config.h defs.h struct.h shmem.h data.h 
util.o : util.c config.h defs.h struct.h data.h shmem.h 
wander2.o : wander2.c config.h defs.h struct.h data.h 
warning.o : warning.c config.h defs.h struct.h data.h packets.h 
weapons.o : weapons.c config.h defs.h struct.h data.h daemonII.h weapons.h shmem.h 
