Makefile revision 100872
11556Srgrimes#
21556Srgrimes# $FreeBSD: head/etc/mail/Makefile 100872 2002-07-29 09:40:17Z ru $
31556Srgrimes#
41556Srgrimes# This Makefile provides an easy way to generate the configuration
51556Srgrimes# file and database maps for the sendmail(8) daemon.
61556Srgrimes#
71556Srgrimes# The user-driven targets are:
81556Srgrimes#
91556Srgrimes# all     - Build cf, maps and aliases
101556Srgrimes# cf      - Build the .cf file from .mc file
111556Srgrimes# maps    - Build the feature maps
121556Srgrimes# aliases - Build the sendmail aliases
131556Srgrimes# install - Install the .cf file as /etc/mail/sendmail.cf
141556Srgrimes#
151556Srgrimes# For acting on both the MTA daemon and MSP queue running daemon:
161556Srgrimes# start        - Start both the sendmail MTA daemon and MSP queue running
171556Srgrimes#                daemon with the flags defined in /etc/defaults/rc.conf or
181556Srgrimes#                /etc/rc.conf
191556Srgrimes# stop         - Stop both the sendmail MTA daemon and MSP queue running
201556Srgrimes#                daemon
211556Srgrimes# restart      - Restart both the sendmail MTA daemon and MSP queue running
221556Srgrimes#                daemon
231556Srgrimes#
241556Srgrimes# For acting on just the MTA daemon:
251556Srgrimes# start-mta    - Start the sendmail MTA daemon with the flags defined in
261556Srgrimes#                /etc/defaults/rc.conf or /etc/rc.conf
271556Srgrimes# stop-mta     - Stop the sendmail MTA daemon
281556Srgrimes# restart-mta  - Restart the sendmail MTA daemon
291556Srgrimes#
301556Srgrimes# For acting on just the MSP queue running daemon:
311556Srgrimes# start-mspq   - Start the sendmail MSP queue running daemon with the
321556Srgrimes#                flags defined in /etc/defaults/rc.conf or /etc/rc.conf
331556Srgrimes# stop-mspq    - Stop the sendmail MSP queue running daemon
341556Srgrimes# restart-mspq - Restart the sendmail MSP queue running daemon
351556Srgrimes#
361556Srgrimes# Calling `make' will generate the updated versions when either the
371556Srgrimes# aliases or one of the map files were changed.
3836150Scharnier#
3936150Scharnier# A `make install` is only necessary after modifying the .mc file. In
4036150Scharnier# this case one would normally also call `make restart' to allow the
4136150Scharnier# running sendmail to pick up the changes as well.
4238535Scracauer#
431556Srgrimes# ------------------------------------------------------------------------
441556Srgrimes# This Makefile uses `<HOSTNAME>.mc' as the default MTA .mc file.  This
4517987Speter# can be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.:
4617987Speter#
4717987Speter#		   SENDMAIL_MC=/etc/mail/myconfig.mc
4817987Speter#
491556Srgrimes# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc'
501556Srgrimes# as a template.
511556Srgrimes#
521556Srgrimes# It also uses 'freebsd.submit.mc' as the default mail submission .mc file.
531556Srgrimes# This can be changed by defining SENDMAIL_SUBMIT_MC in /etc/make.conf,
5417987Speter# e.g.:
551556Srgrimes#
561556Srgrimes#		   SENDMAIL_SUBMIT_MC=/etc/mail/mysubmit.mc
571556Srgrimes# ------------------------------------------------------------------------
581556Srgrimes#
591556Srgrimes# The Makefile knows about the following maps:
601556Srgrimes# access, bitdomain, domaintable, genericstable, mailertable, userdb,
611556Srgrimes# uucpdomain, virtusertable
621556Srgrimes#
631556Srgrimes
641556Srgrimes.ifndef SENDMAIL_MC
651556SrgrimesSENDMAIL_MC!=           hostname
661556SrgrimesSENDMAIL_MC:=           ${SENDMAIL_MC}.mc
671556Srgrimes
681556Srgrimes${SENDMAIL_MC}:
691556Srgrimes	cp freebsd.mc ${SENDMAIL_MC}
701556Srgrimes.endif
711556Srgrimes
721556SrgrimesSENDMAIL_SUBMIT_MC?=	freebsd.submit.mc
731556Srgrimes
741556SrgrimesINSTALL_CF=		${SENDMAIL_MC:R}.cf
751556Srgrimes
761556Srgrimes.ifndef SENDMAIL_SET_USER_ID
7717987SpeterINSTALL_SUBMIT_CF=	${SENDMAIL_SUBMIT_MC:R}.cf
7838521Scracauer.endif
7938521Scracauer
8020902SsteveSENDMAIL_ALIASES?=	/etc/mail/aliases
8138521Scracauer
8238521Scracauer#
8320902Ssteve# This is the directory where the sendmail configuration files are
841556Srgrimes# located.
8517987Speter#
8617987Speter.if exists(/usr/share/sendmail/cf)
8720902SsteveSENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
881556Srgrimes.elif exists(/usr/src/contrib/sendmail/cf)
8920902SsteveSENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
9020902Ssteve.endif
9120902Ssteve
9220902Ssteve#
9320902Ssteve# The sendmail startup script
9420902Ssteve#
9520902SsteveSENDMAIL_START_SCRIPT?=	/etc/rc.sendmail
9620902Ssteve
9720902Ssteve#
9820902Ssteve# Some useful programs we need.
9920902Ssteve#
10020902SsteveSENDMAIL?=		/usr/sbin/sendmail
10120902SsteveMAKEMAP?=		/usr/sbin/makemap
10220902SsteveM4?=			/usr/bin/m4
10320902Ssteve
10420902Ssteve# Permissions for generated maps
10520902SsteveSENDMAIL_MAP_PERMS?=	0640
10620902Ssteve
10720902Ssteve# Set a reasonable default
10820902Ssteve.MAIN:	all
10920902Ssteve
11020902Ssteve#
11120902Ssteve# ------------------------------------------------------------------------
11220902Ssteve#
11320902Ssteve# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
11420902Ssteve# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
11520902Ssteve# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
11620902Ssteve# type to use when calling makemap.
11720902Ssteve#
11820902SsteveSENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
11920902Ssteve			genericstable virtusertable access
12020902SsteveSENDMAIL_MAP_OBJ=
12120902SsteveSENDMAIL_MAP_TYPE?=	hash
12220902Ssteve
12320902Ssteve.for _f in ${SENDMAIL_MAP_SRC} userdb
12420902Ssteve.if exists(${_f})
12520902SsteveSENDMAIL_MAP_OBJ+=	${_f}.db
12620902Ssteve.endif
12720902Ssteve.endfor
12820902Ssteve
12920902Ssteve#
13020902Ssteve# The makemap command is used to generate a hashed map from the textfile.
13120902Ssteve#
13220902Ssteve.for _f in ${SENDMAIL_MAP_SRC}
13320902Ssteve.if (exists(${_f}.sample) && !exists(${_f}))
13420902Ssteve${_f}:		${_f}.sample
1351556Srgrimes	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
1361556Srgrimes.endif
13717987Speter
13817987Speter${_f}.db:	${_f}
13917987Speter	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
14020425Ssteve	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
14117987Speter.endfor
1421556Srgrimes
1431556Srgrimesuserdb.db:	userdb
1441556Srgrimes	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
1451556Srgrimes	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
14620902Ssteve
1471556Srgrimes
14820902Ssteve#
14920902Ssteve# The .cf file needs to be recreated if the templates were modified.
1501556Srgrimes#
1511556SrgrimesM4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
1521556Srgrimes
15320902Ssteve#
15420902Ssteve# M4(1) is used to generate the .cf file from the .mc file.
15520902Ssteve#
15620902Ssteve.SUFFIXES:	.cf .mc
15720902Ssteve
15820902Ssteve.mc.cf:		${M4FILES}
15920902Ssteve	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
16020902Ssteve		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
16120902Ssteve
16220902Ssteve#
16320902Ssteve# Aliases are handled separately since they normally reside in /etc
16420902Ssteve# and can be rebuild without the help of makemap.
16520902Ssteve#
16620902Ssteve${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
16720902Ssteve	${SENDMAIL} -bi
16820902Ssteve	chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
16920902Ssteve
17020902Ssteve#
17120902Ssteve# ------------------------------------------------------------------------
1721556Srgrimes#
1731556Srgrimes
1741556Srgrimesall:		cf maps aliases
1751556Srgrimes
1761556Srgrimesclean:
1771556Srgrimes
1781556Srgrimesdepend:
1791556Srgrimes
1801556Srgrimescf:		${INSTALL_CF} ${INSTALL_SUBMIT_CF}
18120902Ssteve
1821556Srgrimes.ifdef SENDMAIL_SET_USER_ID
1831556Srgrimesinstall: install-cf
1841556Srgrimes.else
1851556Srgrimesinstall: install-cf install-submit-cf
1861556Srgrimes.endif
1871556Srgrimes
1881556Srgrimesinstall-cf:	${INSTALL_CF}
1891556Srgrimes.if ${INSTALL_CF} != /etc/mail/sendmail.cf
1901556Srgrimes	${INSTALL} -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
19120902Ssteve.endif
19220902Ssteve
1931556Srgrimes
1941556Srgrimesinstall-submit-cf:	${INSTALL_SUBMIT_CF}
19520902Ssteve.ifdef SENDMAIL_SET_USER_ID
1961556Srgrimes	@echo ">>> ERROR: You should not create a submit.cf file if you are using a"
1971556Srgrimes	@echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
1981556Srgrimes	@echo "           in make.conf)."
1991556Srgrimes	@false
2001556Srgrimes.else
2011556Srgrimes.if ${INSTALL_SUBMIT_CF} != /etc/mail/submit.cf
2021556Srgrimes	${INSTALL} -m ${SHAREMODE} ${INSTALL_SUBMIT_CF} /etc/mail/submit.cf
2031556Srgrimes.endif
2041556Srgrimes.endif
2051556Srgrimes
2061556Srgrimesaliases:	${SENDMAIL_ALIASES}.db
2071556Srgrimes
2081556Srgrimesmaps:		${SENDMAIL_MAP_OBJ}
2091556Srgrimes
2101556Srgrimesstart start-mta start-mspq:
2111556Srgrimes	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
21231098Sbde		echo -n 'Starting:'; \
21320425Ssteve		sh ${SENDMAIL_START_SCRIPT} $@; \
21417987Speter		echo '.'; \
21517987Speter	fi
2161556Srgrimes
21731098Sbdestop stop-mta stop-mspq:
2181556Srgrimes	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
2191556Srgrimes		echo -n 'Stopping:'; \
2201556Srgrimes		sh ${SENDMAIL_START_SCRIPT} $@; \
2211556Srgrimes		echo '.'; \
2221556Srgrimes	fi
2231556Srgrimes
2241556Srgrimesrestart restart-mta restart-mspq:
2251556Srgrimes	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
22638521Scracauer		echo -n 'Restarting:'; \
2271556Srgrimes		sh ${SENDMAIL_START_SCRIPT} $@; \
2281556Srgrimes		echo '.'; \
22938521Scracauer	fi
2301556Srgrimes
2311556Srgrimes# User defined targets
2321556Srgrimes.if exists(Makefile.local)
2331556Srgrimes.include "Makefile.local"
2341556Srgrimes.endif
2351556Srgrimes
2361556Srgrimes# For the definition of $SHAREMODE
2371556Srgrimes.include <bsd.own.mk>
2381556Srgrimes