SHELL=	 /bin/sh
CC=	 @CC@
INSTALL= @INSTALL@

DEFS=	@DEFS@
LIBS=	@LIBS@

OBJS=	disserve.o atom.o dispatch.o acl.o acl_core.o \
	../libds/tfile.o ../libds/tnet.o ../libds/dsc_et.o ../libds/rpc_et.o

SRCS=	disserve.c core.c coreutil.c atom.c dispatch.c acl.c rpproc.c \
	acl_core.c expunge.c recover.c glue.c

KLIBS=	@KLIBS@

ZLIBS=	@ZLIBS@

INCLUDES=-I../include
KINCLUDES=@KINCLUDES@
CFLAGS= -O
COMERR=../et/libcom_err.a
DLIBS=${ZLIBS} ../libds/libds.a ${KLIBS} ../usp/libusp.a ${COMERR}

all:	disserve discussd debug recover expunge

disserve: ${OBJS} rpproc.nk.o core.o coreutil.o
	rm -f disserve
	${CC} ${CFLAGS} -o disserve ${OBJS} core.o coreutil.o rpproc.nk.o \
		${DLIBS} ${LIBS}

servetest: ../client/discuss.o ../client/cmds.o ../client/libss.a \
		../client/discuss_utils.o core.o coreutil.o atom.o acl.o \
		../libds/tfile.o glue.o
	${CC} ${CFLAGS} -o servetest ../client/discuss.o ../client/cmds.o \
		../client/libss.a ../client/discuss_utils.o core.o coreutil.o \
		atom.o acl.o ../libds/tfile.o glue.o

recover: recover.o core.o coreutil.o atom.o acl.o ../libds/tunix.o \
		../libds/tfile.o glue.o ../libds/dsc_et.o ${COMERR}
	rm -f recover
	${CC} ${CFLAGS} -o recover recover.o core.o coreutil.o atom.o acl.o \
		glue.o ${DLIBS} ${LIBS}

expunge: expunge.o core.o coreutil.o atom.o acl.o acl_core.o \
		../libds/tunix.o ../libds/tfile.o glue.o \
		${COMERR}
	rm -rf expunge
	${CC} ${CFLAGS} -o expunge expunge.o core.o coreutil.o atom.o acl.o \
		acl_core.o glue.o ${DLIBS} ${LIBS}

discussd: ${OBJS} rpproc.k.o core.o coreutil.o
	rm -f discussd
	${CC} ${CFLAGS} -o discussd ${OBJS} core.o coreutil.o rpproc.k.o \
		${DLIBS} ${LIBS}

debug:	disdebug

disdebug: ${OBJS} rpproc.debug.o core.o coreutil.o
	rm -f disdebug
	${CC} ${CFLAGS} -o disdebug ${OBJS} core.o coreutil.o rpproc.debug.o \
		${DLIBS} ${LIBS}

rpproc.k.o: rpproc.c
	rm -f rpproc.k.o rpproc.o
	${CC} ${CFLAGS} ${INCLUDES} ${KINCLUDES} ${DEFS} -DUSPRPC -DINETD -c rpproc.c
	mv rpproc.o rpproc.k.o

rpproc.nk.o: rpproc.c
	rm -f rpproc.o rpproc.nk.o
	${CC} ${CFLAGS} ${INCLUDES} ${DEFS} -DUSPRPC -DSUBPROC -c rpproc.c
	mv rpproc.o rpproc.nk.o

rpproc.debug.o: rpproc.c
	rm -f rpproc.debug.o rpproc.o
	${CC} ${CFLAGS} ${INCLUDES} ${KINCLUDES} ${DEFS} -DUSPRPC -c rpproc.c
	mv rpproc.o rpproc.debug.o

clean:
	rm -f *.o *~ \#* disserve recover expunge discussd disdebug

install: discussd disserve
	install -c discussd ${SERVERDIR}/discussd
	-/etc/chown discuss ${SERVERDIR}/discussd
	install -c -m 4755 disserve ${SERVERDIR}/disserve
	-/etc/chown discuss ${SERVERDIR}/disserve

dist:	${SRCS} Makefile mtg.h
	-mkdir ../../dist/source/server
	-chmod g+w ../../dist/source/server
	cp -p ${SRCS} ../../dist/source/server/
	cp -p Makefile.in ../../dist/source/server/
	cp -p mtg.h ../../dist/source/server/

.c.o:
	rm -rf $*.o
	${CC} ${CFLAGS} ${INCLUDES} ${DEFS} -c $*.c
