Makefile revision 95317
172847Sgshapiro#
250472Speter# $FreeBSD: head/etc/mail/Makefile 95317 2002-04-23 17:08:08Z 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
10472847Sgshapiro# Set a reasonable default
10572847Sgshapiro.MAIN:	all
10657947Srwatson
10772847Sgshapiro#
10872847Sgshapiro# ------------------------------------------------------------------------
10972847Sgshapiro#
11072847Sgshapiro# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
11172847Sgshapiro# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
11275074Sgshapiro# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
11375074Sgshapiro# type to use when calling makemap.
11472847Sgshapiro#
11572847SgshapiroSENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
11675073Sgshapiro			genericstable virtusertable access
11772847SgshapiroSENDMAIL_MAP_OBJ=
11875074SgshapiroSENDMAIL_MAP_TYPE?=	hash
11957947Srwatson
12075073Sgshapiro.for _f in ${SENDMAIL_MAP_SRC} userdb
12172847Sgshapiro.if exists(${_f})
12272847SgshapiroSENDMAIL_MAP_OBJ+=	${_f}.db
12372847Sgshapiro.endif
12472847Sgshapiro.endfor
12557947Srwatson
12672847Sgshapiro#
12772847Sgshapiro# The makemap command is used to generate a hashed map from the textfile.
12872847Sgshapiro#
12972847Sgshapiro.for _f in ${SENDMAIL_MAP_SRC}
13072847Sgshapiro.if (exists(${_f}.sample) && !exists(${_f}))
13172847Sgshapiro${_f}:		${_f}.sample
13272847Sgshapiro	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
13372847Sgshapiro.endif
13472847Sgshapiro
13572847Sgshapiro${_f}.db:	${_f}
13675074Sgshapiro	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
13772847Sgshapiro.endfor
13872847Sgshapiro
13975073Sgshapirouserdb.db:	userdb
14075073Sgshapiro	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
14175073Sgshapiro
14275073Sgshapiro
14372847Sgshapiro#
14472847Sgshapiro# The .cf file needs to be recreated if the templates were modified.
14572847Sgshapiro#
14672847SgshapiroM4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
14772847Sgshapiro
14872847Sgshapiro#
14972847Sgshapiro# M4(1) is used to generate the .cf file from the .mc file.
15072847Sgshapiro#
15172847Sgshapiro.SUFFIXES:	.cf .mc
15272847Sgshapiro
15372847Sgshapiro.mc.cf:		${M4FILES}
15480175Sgshapiro	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
15580175Sgshapiro		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
15672847Sgshapiro
15772847Sgshapiro#
15872847Sgshapiro# Aliases are handled separately since they normally reside in /etc
15972847Sgshapiro# and can be rebuild without the help of makemap.
16072847Sgshapiro#
16172847Sgshapiro${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
16272847Sgshapiro	${SENDMAIL} -bi
16372847Sgshapiro
16472847Sgshapiro#
16572847Sgshapiro# ------------------------------------------------------------------------
16672847Sgshapiro#
16772847Sgshapiro
16872847Sgshapiroall:		cf maps aliases
16972847Sgshapiro
17057947Srwatsonclean:
17172847Sgshapiro
17272847Sgshapirodepend:
17372847Sgshapiro
17494676Sgshapirocf:		${INSTALL_CF} ${INSTALL_SUBMIT_CF}
17572847Sgshapiro
17690806Sgshapiro.ifdef SENDMAIL_SET_USER_ID
17794676Sgshapiroinstall: install-cf
17894676Sgshapiro.else
17994676Sgshapiroinstall: install-cf install-submit-cf
18094676Sgshapiro.endif
18194676Sgshapiro
18294676Sgshapiroinstall-cf:	${INSTALL_CF}
18394676Sgshapiro.if ${INSTALL_CF} != /etc/mail/sendmail.cf
18494676Sgshapiro	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
18594676Sgshapiro.endif
18694676Sgshapiro
18794676Sgshapiro
18894676Sgshapiroinstall-submit-cf:	${INSTALL_SUBMIT_CF}
18994676Sgshapiro.ifdef SENDMAIL_SET_USER_ID
19090806Sgshapiro	@echo ">>> ERROR: You should not create a submit.cf file if you are using a"
19190806Sgshapiro	@echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
19290806Sgshapiro	@echo "           in make.conf)."
19390806Sgshapiro	@false
19494676Sgshapiro.else
19594676Sgshapiro.if ${INSTALL_SUBMIT_CF} != /etc/mail/submit.cf
19694676Sgshapiro	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_SUBMIT_CF} /etc/mail/submit.cf
19790806Sgshapiro.endif
19894676Sgshapiro.endif
19990806Sgshapiro
20072847Sgshapiroaliases:	${SENDMAIL_ALIASES}.db
20172847Sgshapiro
20294676Sgshapiromaps:		${SENDMAIL_MAP_OBJ}
20372847Sgshapiro
20493853Sgshapirostart start-mta start-mspq:
20593853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
20693853Sgshapiro		echo -n 'Starting:'; \
20793853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
20893853Sgshapiro		echo '.'; \
20993853Sgshapiro	fi
21072847Sgshapiro
21193853Sgshapirostop stop-mta stop-mspq:
21293853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
21393853Sgshapiro		echo -n 'Stopping:'; \
21493853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
21593853Sgshapiro		echo '.'; \
21693853Sgshapiro	fi
21772847Sgshapiro
21893853Sgshapirorestart restart-mta restart-mspq:
21993853Sgshapiro	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
22093853Sgshapiro		echo -n 'Restarting:'; \
22193853Sgshapiro		sh ${SENDMAIL_START_SCRIPT} $@; \
22293853Sgshapiro		echo '.'; \
22393853Sgshapiro	fi
22476623Sgshapiro
22576623Sgshapiro# User defined targets
22676623Sgshapiro.if exists(Makefile.local)
22776623Sgshapiro.include "Makefile.local"
22876623Sgshapiro.endif
22995317Sgshapiro
23095317Sgshapiro# For the definition of $SHAREMODE
23195317Sgshapiro.include <bsd.own.mk>
232