# $Id$
#
# Makefile for administration of sendmail on Mac OS X.
#
# Place this file under /etc/mail, then change into the /etc/mail
# directory, and use the following commands to perform various sendmail
# administrative tasks.
#
# make all         Calls config and maps rules (default rule).
# make config      Rebuilds the *.cf files if needed.
# make maps        Rebuilds any hashed MAPFILES.
# make reload      Tells sendmail to relaunch itself.
# make clean       Removes various old or temporary files.
# make distclean   Above plus the *.cf and hashed MAPFILES.
# This is where Mac OS X keeps the sendmail cf directory
CFDIR?=    /usr/share/sendmail/conf
# Where various things are located
M4?=       m4
MAKEMAP?=  /usr/sbin/makemap
SENDMAIL=  /usr/sbin/sendmail
PIDFILE=   /var/run/sendmail.pid
# how and what to hash with makemap(8)
HASHTYPE?= hash
MAPFILES+= access genericstable mailertable virtusertable
# for reference
CFM4=      $(CFDIR)/m4/cf.m4
MCFILE=    sendmail.mc
CFFILE=    sendmail.cf
SMMCFILE=  submit.mc
SMFILE=    submit.cf
PWD=       `/bin/pwd`
LOGGER=    logger -i -p mail.info -t sm-makefile
all: config maps
maps:
	@$(LOGGER) rebuilding mapped files in $(PWD)
	@for F in $(MAPFILES); do \
	   if [ -f $$F ]; then \
	     $(MAKEMAP) $(HASHTYPE) $$F < $$F; \
	   fi \
	 done
	@if [ -f userdb ]; then \
	   $(MAKEMAP) btree userdb < userdb; \
	 fi
config: $(CFFILE) $(SMFILE) $(CFM4)
$(CFFILE): $(MCFILE) $(CFM4)
	@$(LOGGER) rebuilding $(CFFILE) in $(PWD)
	@-cp $(CFFILE) $(CFFILE).old 2>/dev/null || true
	@$(M4) -D_CF_DIR_=$(CFDIR)/ $(CFM4) $(MCFILE) > $(CFFILE)
$(SMFILE): $(SMMCFILE) $(CFM4)
	@$(LOGGER) rebuilding $(SMFILE) in $(PWD)
	@-cp $(SMFILE) $(SMFILE).old 2>/dev/null || true
	@$(M4) -D_CF_DIR_=$(CFDIR)/ $(CFM4) $(SMMCFILE) > $(SMFILE)
reload: $(CFFILE) $(PIDFILE)
	@kill -HUP `head -1 $(PIDFILE)`
clean:
	@rm -f *~ *.old
distclean: clean
	@rm -f *.db *.pag *.dir $(CFFILE)* $(SMFILE)*