Makefile revision 110576
172847Sgshapiro#
250472Speter# $FreeBSD: head/etc/mail/Makefile 110576 2003-02-08 21:55:31Z gshapiro $
372847Sgshapiro#
472847Sgshapiro# This Makefile provides an easy way to generate the configuration
572847Sgshapiro# file and database maps for the sendmail(8) daemon.
672847Sgshapiro#
772847Sgshapiro# The user-driven targets are:
872847Sgshapiro#
972847Sgshapiro# all     - Build cf, maps and aliases
1072847Sgshapiro# cf      - Build the .cf file from .mc file
1172847Sgshapiro# maps    - Build the feature maps
1272847Sgshapiro# aliases - Build the sendmail aliases
1372847Sgshapiro# install - Install the .cf file as /etc/mail/sendmail.cf
1493315Sgshapiro#
1593853Sgshapiro# For acting on both the MTA daemon and MSP queue running daemon:
1693853Sgshapiro# start        - Start both the sendmail MTA daemon and MSP queue running
1793853Sgshapiro#                daemon with the flags defined in /etc/defaults/rc.conf or
1893853Sgshapiro#                /etc/rc.conf
1993853Sgshapiro# stop         - Stop both the sendmail MTA daemon and MSP queue running
2093853Sgshapiro#                daemon
2193853Sgshapiro# restart      - Restart both the sendmail MTA daemon and MSP queue running
2293853Sgshapiro#                daemon
2372847Sgshapiro#
2493853Sgshapiro# For acting on just the MTA daemon:
2593853Sgshapiro# start-mta    - Start the sendmail MTA daemon with the flags defined in
2693853Sgshapiro#                /etc/defaults/rc.conf or /etc/rc.conf
2793853Sgshapiro# stop-mta     - Stop the sendmail MTA daemon
2893853Sgshapiro# restart-mta  - Restart the sendmail MTA daemon
2993853Sgshapiro#
3093853Sgshapiro# For acting on just the MSP queue running daemon:
3193315Sgshapiro# start-mspq   - Start the sendmail MSP queue running daemon with the
3293315Sgshapiro#                flags defined in /etc/defaults/rc.conf or /etc/rc.conf
3393315Sgshapiro# stop-mspq    - Stop the sendmail MSP queue running daemon
3493315Sgshapiro# restart-mspq - Restart the sendmail MSP queue running daemon
3593315Sgshapiro#
3672847Sgshapiro# Calling `make' will generate the updated versions when either the
3772847Sgshapiro# aliases or one of the map files were changed.
3872847Sgshapiro#
3972847Sgshapiro# A `make install` is only necessary after modifying the .mc file. In
4072847Sgshapiro# this case one would normally also call `make restart' to allow the
4172847Sgshapiro# running sendmail to pick up the changes as well.
4272847Sgshapiro#
4372847Sgshapiro# ------------------------------------------------------------------------
4494676Sgshapiro# This Makefile uses `<HOSTNAME>.mc' as the default MTA .mc file.  This
4594676Sgshapiro# can be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.:
4672847Sgshapiro#
4772847Sgshapiro#		   SENDMAIL_MC=/etc/mail/myconfig.mc
4872847Sgshapiro#
4976622Sgshapiro# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc'
5076622Sgshapiro# as a template.
5194676Sgshapiro#
5294676Sgshapiro# It also uses 'freebsd.submit.mc' as the default mail submission .mc file.
5394676Sgshapiro# This can be changed by defining SENDMAIL_SUBMIT_MC in /etc/make.conf,
5494676Sgshapiro# e.g.:
5594676Sgshapiro#
5694676Sgshapiro#		   SENDMAIL_SUBMIT_MC=/etc/mail/mysubmit.mc
5772847Sgshapiro# ------------------------------------------------------------------------
5872847Sgshapiro#
5972847Sgshapiro# The Makefile knows about the following maps:
6072847Sgshapiro# access, bitdomain, domaintable, genericstable, mailertable, userdb,
6172847Sgshapiro# uucpdomain, virtusertable
6272847Sgshapiro#
6339146Sbrian
6476622Sgshapiro.ifndef SENDMAIL_MC
6576622SgshapiroSENDMAIL_MC!=           hostname
6676622SgshapiroSENDMAIL_MC:=           ${SENDMAIL_MC}.mc
6776622Sgshapiro
6884684Sgshapiro${SENDMAIL_MC}:
6976622Sgshapiro	cp freebsd.mc ${SENDMAIL_MC}
7076622Sgshapiro.endif
7176622Sgshapiro
7294676SgshapiroSENDMAIL_SUBMIT_MC?=	freebsd.submit.mc
7394676Sgshapiro
7473209SgshapiroINSTALL_CF=		${SENDMAIL_MC:R}.cf
7530581Sjmb
7694676Sgshapiro.ifndef SENDMAIL_SET_USER_ID
7794676SgshapiroINSTALL_SUBMIT_CF=	${SENDMAIL_SUBMIT_MC:R}.cf
7894676Sgshapiro.endif
7994676Sgshapiro
8072847SgshapiroSENDMAIL_ALIASES?=	/etc/mail/aliases
8157947Srwatson
8272847Sgshapiro#
8372847Sgshapiro# This is the directory where the sendmail configuration files are
8472847Sgshapiro# located.
8572847Sgshapiro#
8672847Sgshapiro.if exists(/usr/share/sendmail/cf)
8772847SgshapiroSENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
8893765Sru.elif exists(/usr/src/contrib/sendmail/cf)
8993765SruSENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
9072847Sgshapiro.endif
9157947Srwatson
9272847Sgshapiro#
9393853Sgshapiro# The sendmail startup script
9472847Sgshapiro#
9593853SgshapiroSENDMAIL_START_SCRIPT?=	/etc/rc.sendmail
9657947Srwatson
9772847Sgshapiro#
9872847Sgshapiro# Some useful programs we need.
9972847Sgshapiro#
10072847SgshapiroSENDMAIL?=		/usr/sbin/sendmail
10172847SgshapiroMAKEMAP?=		/usr/sbin/makemap
10272847SgshapiroM4?=			/usr/bin/m4
10364567Sgshapiro
10497200Sgshapiro# Permissions for generated maps
10597200SgshapiroSENDMAIL_MAP_PERMS?=	0640
10697200Sgshapiro
10772847Sgshapiro# Set a reasonable default
10872847Sgshapiro.MAIN:	all
10957947Srwatson
11072847Sgshapiro#
11172847Sgshapiro# ------------------------------------------------------------------------
11272847Sgshapiro#
11372847Sgshapiro# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
11472847Sgshapiro# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
11575074Sgshapiro# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
11675074Sgshapiro# type to use when calling makemap.
11772847Sgshapiro#
11872847SgshapiroSENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
11975073Sgshapiro			genericstable virtusertable access
12072847SgshapiroSENDMAIL_MAP_OBJ=
12175074SgshapiroSENDMAIL_MAP_TYPE?=	hash
12257947Srwatson
12375073Sgshapiro.for _f in ${SENDMAIL_MAP_SRC} userdb
12472847Sgshapiro.if exists(${_f})
12572847SgshapiroSENDMAIL_MAP_OBJ+=	${_f}.db
12672847Sgshapiro.endif
12772847Sgshapiro.endfor
12857947Srwatson
12972847Sgshapiro#
13072847Sgshapiro# The makemap command is used to generate a hashed map from the textfile.
13172847Sgshapiro#
13272847Sgshapiro.for _f in ${SENDMAIL_MAP_SRC}
13372847Sgshapiro.if (exists(${_f}.sample) && !exists(${_f}))
13472847Sgshapiro${_f}:		${_f}.sample
13572847Sgshapiro	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
13672847Sgshapiro.endif
13772847Sgshapiro
13872847Sgshapiro${_f}.db:	${_f}
13975074Sgshapiro	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
14097200Sgshapiro	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
14172847Sgshapiro.endfor
14272847Sgshapiro
14375073Sgshapirouserdb.db:	userdb
14475073Sgshapiro	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
14597200Sgshapiro	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
14675073Sgshapiro
14775073Sgshapiro
14872847Sgshapiro#
14972847Sgshapiro# The .cf file needs to be recreated if the templates were modified.
15072847Sgshapiro#
15172847SgshapiroM4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
15272847Sgshapiro
15372847Sgshapiro#
15472847Sgshapiro# M4(1) is used to generate the .cf file from the .mc file.
15572847Sgshapiro#
15672847Sgshapiro.SUFFIXES:	.cf .mc
15772847Sgshapiro
15872847Sgshapiro.mc.cf:		${M4FILES}
15980175Sgshapiro	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
16080175Sgshapiro		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
16172847Sgshapiro
16272847Sgshapiro#
16372847Sgshapiro# Aliases are handled separately since they normally reside in /etc
16472847Sgshapiro# and can be rebuild without the help of makemap.
16572847Sgshapiro#
166110576Sgshapiro.for _f in ${SENDMAIL_ALIASES}
167110576Sgshapiro${_f}.db:	${_f}
168110576Sgshapiro	${SENDMAIL} -bi -OAliasFile=${.ALLSRC}
16997200Sgshapiro	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
170110576Sgshapiro.endfor
17172847Sgshapiro
17272847Sgshapiro#
17372847Sgshapiro# ------------------------------------------------------------------------
17472847Sgshapiro#
17572847Sgshapiro
17672847Sgshapiroall:		cf maps aliases
17772847Sgshapiro
17857947Srwatsonclean:
17972847Sgshapiro
18072847Sgshapirodepend:
18172847Sgshapiro
18294676Sgshapirocf:		${INSTALL_CF} ${INSTALL_SUBMIT_CF}
18372847Sgshapiro
18490806Sgshapiro.ifdef SENDMAIL_SET_USER_ID
18594676Sgshapiroinstall: install-cf
18694676Sgshapiro.else
18794676Sgshapiroinstall: install-cf install-submit-cf
18894676Sgshapiro.endif
18994676Sgshapiro
19094676Sgshapiroinstall-cf:	${INSTALL_CF}
19194676Sgshapiro.if ${INSTALL_CF} != /etc/mail/sendmail.cf
192100872Sru	${INSTALL} -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
19394676Sgshapiro.endif
19494676Sgshapiro
19594676Sgshapiro
19694676Sgshapiroinstall-submit-cf:	${INSTALL_SUBMIT_CF}
19794676Sgshapiro.ifdef SENDMAIL_SET_USER_ID
19890806Sgshapiro	@echo ">>> ERROR: You should not create a submit.cf file if you are using a"
19990806Sgshapiro	@echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
20090806Sgshapiro	@echo "           in make.conf)."
20190806Sgshapiro	@false
20294676Sgshapiro.else
20394676Sgshapiro.if ${INSTALL_SUBMIT_CF} != /etc/mail/submit.cf
204100872Sru	${INSTALL} -m ${SHAREMODE} ${INSTALL_SUBMIT_CF} /etc/mail/submit.cf
20590806Sgshapiro.endif
20694676Sgshapiro.endif
20790806Sgshapiro
208110576Sgshapiroaliases:	${SENDMAIL_ALIASES:%=%.db}
20972847Sgshapiro
21094676Sgshapiromaps:		${SENDMAIL_MAP_OBJ}
21172847Sgshapiro
21293853Sgshapirostart start-mta start-mspq:
21393853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
21493853Sgshapiro		echo -n 'Starting:'; \
21593853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
21693853Sgshapiro		echo '.'; \
21793853Sgshapiro	fi
21872847Sgshapiro
21993853Sgshapirostop stop-mta stop-mspq:
22093853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
22193853Sgshapiro		echo -n 'Stopping:'; \
22293853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
22393853Sgshapiro		echo '.'; \
22493853Sgshapiro	fi
22572847Sgshapiro
22693853Sgshapirorestart restart-mta restart-mspq:
22793853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
22893853Sgshapiro		echo -n 'Restarting:'; \
22993853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
23093853Sgshapiro		echo '.'; \
23193853Sgshapiro	fi
23276623Sgshapiro
23376623Sgshapiro# User defined targets
23476623Sgshapiro.if exists(Makefile.local)
23576623Sgshapiro.include "Makefile.local"
23676623Sgshapiro.endif
23795317Sgshapiro
23895317Sgshapiro# For the definition of $SHAREMODE
23995317Sgshapiro.include <bsd.own.mk>
240