# Makefile to setup mh queue management stuff and install queues
#
# For this stuff to work, you must have MH already installed.
#
# Ok, so you didn't read ManagingQueueMH like the README told you to do.
#   -	Make sure the macros are how you want them
#   -	make install
#   -	make queue
#   -   for each additional queues, change QUEUE, QUID, QGID,
#	and make queue again
#   -	each user that will operate on the queue needs to be added
#	to the $(QUEUE) group and run $(SETUP)/install $(QUEUE)
#   -	Now go RTFM
#
# Customize this section
#
CFLAGS	=	-O
#
# Where was MH installed
#
MHBIN	=	/usr/local/mh/bin
MHLIB	=	/usr/local/mh/lib
#
# Installation paths
#
OPSBIN	=	/usr/local/adm/csops/bin
SETUP	=	/usr/local/adm/csops/mhsetup
DESTDIR	=	/usr/local/adm/csops
MANSUFF =	l
PASSWD	=	/etc/passwd
GROUP	=	/etc/group
#
# Group owner of executables
XGRP	=	staff
#
# Info to create fake MH user for mail queue
#
# name of the mail queue, fake user and group
# making these two names different requires a small hack to res and stat
QUEUE	=	trouble
#
# uid/gid for the fake user
QUID	=	71
QGID	=	71
#
# home dir for the fake user
QHOME	=	/`hostname`/$(XGRP)/$(QUEUE)
#
# alias list to cc on all queue status replies
QREPL	=	$(QUEUE)mr
#
# alias list to cc on all queue resolves
QRES	=	$(QREPL), ops
#
#
#
# You shouldn't have to edit past this point - it might break something.
#
SHELL	=	/bin/sh
#
# Files
#
EXEC	=	src/tmhappend src/tmhedit
SCRIPTS	=	bin/res bin/stat bin/glom bin/notack

DOC	=	doc/UsingQueueMH

UFILES	=	setup/.mh_profile setup/install

UMAIL	=	setup/Mail/aliases setup/Mail/components setup/Mail/forwcomps \
		setup/Mail/mhl.format setup/Mail/repl.format

QFILES	=	quser/.forward quser/.maildelivery quser/.mh_profile

QMAIL	=	quser/Mail/replcomps quser/Mail/rescomps \
		quser/Mail/aliases  quser/Mail/components \
		quser/Mail/context quser/Mail/forwcomps \
		quser/Mail/glom.body.format quser/Mail/repl.format

MAN	=	stat res glom notack

#
# Stuff to mung paths and things into script and format files
#
.SUFFIXES:	.mh

.mh:;		sed -e	's:/usr/new/mh:$(MHBIN):' \
		    -e	's:/usr/local/adm/csops:$(DESTDIR):' \
		    -e	's:QUSER:$(QUEUE):' -e 's:QUEUE:$(QUEUE):' \
		    -e	's:/usr/new/lib/mh:$(MHLIB):' \
		    -e	's:TMR:$(QREPL):g' -e 's:RESMR:$(QRES):g' $< > $@
#
# Actually do something
#
all: $(EXEC) $(SCRIPTS) $(UFILES) $(UMAIL) $(QFILES) $(QMAIL) $(DOC)

install: $(EXEC) $(SCRIPTS) $(UFILES) $(UMAIL)
	if [ ! -d $(OPSBIN) ]; then \
	    mkdir -p $(OPSBIN); \
	fi
	install -g $(XGRP) -m 0750 -o root $(EXEC) $(SCRIPTS) $(OPSBIN)
	for page in $(MAN); do \
	    install -g $(XGRP) -m 0644 -o root man/$${page}.l \
		/usr/man/man$(MANSUFF)/$${page}.$(MANSUFF); \
	done
	if [ ! -d $(SETUP) ]; then \
	    mkdir -p $(SETUP)/Mail; \
	fi
	install -g $(XGRP) -m 0750 -o root $(UFILES) $(SETUP)
	install -g $(XGRP) -m 0640 -o root $(UMAIL) $(SETUP)/Mail

queue: $(QFILES) $(QMAIL) $(DOC)
	echo "$(QUEUE):*:$(QUID):$(QGID):MH $(QUEUE) fake:$(QHOME):/bin/fake" \
		>> $(PASSWD)
	echo "$(QUEUE):*:$(QGID):" >> $(GROUP)
	install -d -g $(QUEUE) -m 2750 -o $(QUEUE) $(QHOME)
	install -d -g $(QUEUE) -m 2750 -o $(QUEUE) $(QHOME)/Mail
	install -d -g $(QUEUE) -m 2770 -o $(QUEUE) $(QHOME)/Mail/$(QUEUE)
	install -d -g $(QUEUE) -m 2750 -o $(QUEUE) $(QHOME)/Mail/trap
	install -g $(QUEUE) -m 0640 -o $(QUEUE) $(QFILES) $(QHOME)
	install -g $(QUEUE) -m 0640 -o $(QUEUE) $(QMAIL) $(QHOME)/Mail
	cp $(DOC) doc/Using$(QUEUE)MH

clean:
	rm -f $(QFILES) $(QMAIL) $(DOC)

scrub:
	rm -f $(EXEC) $(SCRIPTS) $(UFILES) $(QFILES) $(QMAIL) $(DOC)
