SHELL=	     /bin/sh
srcdir=      @srcdir@
CC=	     @CC@
INSTALL=     @INSTALL@
prefix=      @prefix@
exec_prefix= @exec_prefix@
sbindir=     @sbindir@
SERVERDIR=   $(sbindir)

DEFS=	 @DEFS@
LIBS=	 @LIBS@
OBJS=	 disserve.o atom.o core.o coreutil.o acl_core.o dispatch.o
ROBJS=   recover.o  atom.o core.o coreutil.o
EOBJS=   expunge.o  atom.o core.o coreutil.o acl_core.o
KLIBS=	 @KLIBS@
ZLIBS=	 @ZLIBS@
INCLUDES=-I../include -I$(prefix)/include
CFLAGS=  -O $(INCLUDES) $(DEFS) $(KINCLUDES)
LDFLAGS= -L$(prefix)/lib
ETLIB=   -lcom_err
DLIBS=   ${ZLIBS} ${LIBDS} ${KLIBS} ../usp/libusp.a ${ETLIB} ${LIBS}
#LIBDS=  ../libds/libds.a
LIBDS=   ../libds/acl.o ../libds/tfile.o ../libds/tnet.o ../libds/tunix.o \
	 ../libds/realm.o ../libds/dsc_et.o ../libds/rpc_et.o


all:	discussd disserve disdebug recover expunge

discussd: ${OBJS} rpproc-k.o
	rm -f discussd
	${CC} ${LDFLAGS} -o discussd ${OBJS} rpproc-k.o ${DLIBS}

disserve: ${OBJS} rpproc-nk.o
	rm -f disserve
	${CC} ${LDFLAGS} -o disserve ${OBJS} rpproc-nk.o ${DLIBS}

disdebug: ${OBJS} rpproc-debug.o
	rm -f disdebug
	${CC} ${LDFLAGS} -o disdebug ${OBJS} rpproc-debug.o ${DLIBS}

recover: ${ROBJS}
	rm -f recover
	${CC} ${LDFLAGS} -o recover ${ROBJS} ${DLIBS}

expunge: ${EOBJS}
	rm -rf expunge
	${CC} ${LDFLAGS} -o expunge ${EOBJS} ${DLIBS}

rpproc-k.o: rpproc-k.c
rpproc-k.c: rpproc.c
	rm -f rpproc-k.c
	echo '#define USPRPC'	 >rpproc-k.c
	echo '#define INETD'	>>rpproc-k.c
	cat $(srcdir)/rpproc.c	>>rpproc-k.c

rpproc-nk.o: rpproc-nk.c
rpproc-nk.c: rpproc.c
	rm -f rpproc-nk.c
	echo '#define USPRPC'	 >rpproc-nk.c
	echo '#define SUBPROC'	>>rpproc-nk.c
	cat $(srcdir)/rpproc.c	>>rpproc-nk.c

rpproc-debug.o: rpproc-debug.c
rpproc-debug.c: rpproc.c
	rm -f rpproc-debug.c
	echo '#define USPRPC'	 >rpproc-debug.c
	cat $(srcdir)/rpproc.c	>>rpproc-debug.c

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

distclean: clean
	rm -f Makefile rpproc-k.c rpproc-nk.c rpproc-debug.c

install: discussd disserve
	$(INSTALL) -s discussd ${SERVERDIR}
	-chown discuss ${SERVERDIR}/discussd
	$(INSTALL) -s disserve ${SERVERDIR}
	-chown discuss ${SERVERDIR}/disserve && chmod 4755 ${SERVERDIR}/disserve
