# %W% (UKC) %G%
#
# Makefile for remotely-executing troff stuff.
#	Martin Guy, UKC, 21 Sep 1988

# Where the various bits are installed

CFLAGS = -O
LDFLAGS = -X

# Which sources to include in "make tags"
TAGSRC = rexinit.c rexboot.c rpccalls.c trans.c

# object programs to ramove in make clean
PROGS=rexinit rexboot rpcsrv dorexinit selex troff_rexd

all: rpcsrv rex.o rexboot rexinit troff_rexd dorexinit

install:
	@echo 'make inst-server on the central troff engine;'
	@echo 'make inst-client on machines that are to use it.'

# Install bits on the central troff engine.
inst-server: troff_rexd rexboot
	-mkdir /etc/rexsrv && chmod 700 /etc/rexsrv
	install -s troff_rexd /etc/rexsrv/troff
	install -s -m 700 rexboot /etc/ringsrv/rexboot

# Install the bits which each client needs.
inst-client: rexinit rpcsrv
	install -s rexinit /etc/rexinit
	install -s rpcsrv /etc/rpcsrv
	rm -f /usr/lib/ditroff
	ln -s /etc/rexinit /usr/lib/ditroff/troff
	: The following two lines force troff to be used under the
	: UKC batch system.
	-mkdir /usr/lib/batch && chgrp batch1 /usr/lib/batch && chmod 750 /usr/lib/batch
	/etc/batch/forceba troff /usr/lib/ditroff/troff /usr/lib/ditroff/troff

rpcsrv: rpcsrv.o trans.o
	cc ${CFLAGS} -o rpcsrv rpcsrv.o trans.o

rexboot: rexboot.o trans.o rexversion.o
	cc $(CFLAGS) -o rexboot rexboot.o trans.o rexversion.o -ltsb

rexinit: rexinit.o trans.o rexversion.o
	cc $(CFLAGS) -o rexinit rexinit.o trans.o rexversion.o -ltsb

dorexinit: dorexinit.c
	cc $(CFLAGS) -o dorexinit dorexinit.c

rex.o: rexcalls.o trans.o cmds.h selex rex.hide
	cp trans.o t#.o
	selex t#.o __exit _close _fstat _ioctl _read _write _kill _getpid
	ld $(LDFLAGS) -X -r -o rex.o rexcalls.o t#.o
	selex rex.o `cat rex.hide`

rexcalls.o: rpccalls.c
	cc ${CFLAGS} -c -DREX rpccalls.c
	mv rpccalls.o rexcalls.o

trans.o: trans.c
	cc ${CFLAGS} -c trans.c
	ld $(LDFLAGS) -X -r trans.o -ltsb -lc
	mv a.out trans.o

selex: selex.c
	cc $(LDFLAGS) ${CFLAGS} -o selex selex.c

# the remotely executing troff binary
troff_rexd: rex.o trobs
	cc $(CFLAGS) -o troff_rexd ../ditroff/trobs/*.o rex.o

trobs:
	cd ../ditroff; make ditroff

tags: $(TAGSRC)
	ctags $(TAGSRC)

clean:
	rm -f *.o errs $(PROGS)

rexboot.o: trans.h config.h
rexinit.o: trans.h config.h
rpcsrv: cmds.h trans.h
