SHELL=	     /bin/sh
CC=	     @CC@
INSTALL=     @INSTALL@
YACC=	     @YACC@
prefix =     @prefix@
exec_prefix= @exec_prefix@
bindir=      @bindir@
datadir=     @datadir@
INFODIR=     $(datadir)/discuss/info

COMPILE_ET=	compile_et
MK_CMDS=	mk_cmds

DEFS=	@DEFS@
LIBS=	@LIBS@

KLIBS=	@KLIBS@
ETLIB=	-lcom_err
SSLIB=	-lss

INCLUDES= -I../include -I$(prefix)/include
CFLAGS=	  -O
LDFLAGS=  -L$(prefix)/lib

OBJS=	discuss.o output.o trn_expr.o list.o trn_select.o \
	status.o new_trans.o print.o lsm.o addmtg.o list_acl.o \
	interrupt.o goto.o reply.o ckm.o anm.o \
	time.o data.o \
	cmds.o discuss_err.o rn.o randrp.o catchup.o set.o edit.o

SRCS=	discuss.c edit.c output.c trn_expr.c list.c trn_select.c \
	status.c new_trans.c print.c lsm.c addmtg.c list_acl.c \
	interrupt.c goto.c reply.c ckm.c anm.c \
	time.c data.c rn.c randrp.c catchup.c set.c cmds.c edit.c

.SUFFIXES:	.h

all:	discuss

discuss: $(OBJS) ../libds/libds.a ../usp/libusp.a
	-rm -f discuss
	${CC} $(LDFLAGS) -o $@ $(OBJS) ../libds/libds.a ${KLIBS} ../usp/libusp.a ${SSLIB} ${ETLIB} ${LIBS}

discuss.o: discuss.c
	${CC} ${CFLAGS} ${INCLUDES} ${DEFS} -DINFO_DIR=\"${INFODIR}\" -c $*.c

.y.o:	
	-rm -f $*.o y.tab.c y.tab.o
	${YACC} $(YFLAGS) $<
	${CC} $(CFLAGS) -c y.tab.c
	mv y.tab.o $@

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

cmds.o : cmds.c

cmds.c : cmds.ct
	$(MK_CMDS) cmds.ct

discuss_err.c discuss_err.h: ../ets/discuss_err.et
	$(COMPILE_ET) ../ets/discuss_err.et

TAGS:	$(SRCS)
	-etags $(SRCS)

install: all info.tar
	$(INSTALL) -s discuss $(bindir)
	$(INSTALL) -d $(INFODIR)
	cat info.tar | ( cd $(INFODIR) ; tar xvf - )

clean:
	rm -f *.o *~ \#* *.bak
	rm -f discuss trn_expr.c y.tab.c TAGS
#	rm -f info.tar

distclean: clean
	rm -f Makefile discuss_err.c discuss_err.h y.tab.c trn_expr.c

$(OBJS): discuss_err.h
