Makefile revision 90806
172847Sgshapiro#
250472Speter# $FreeBSD: head/etc/mail/Makefile 90806 2002-02-17 22:12:57Z 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
1472847Sgshapiro# start   - Start the sendmail daemon with the flags defined in
1572847Sgshapiro#           /etc/defaults/rc.conf or /etc/rc.conf
1672847Sgshapiro# stop    - Stop the sendmail daemon
1772847Sgshapiro# restart - Restart the sendmail daemon
1872847Sgshapiro#
1972847Sgshapiro# Calling `make' will generate the updated versions when either the
2072847Sgshapiro# aliases or one of the map files were changed.
2172847Sgshapiro#
2272847Sgshapiro# A `make install` is only necessary after modifying the .mc file. In
2372847Sgshapiro# this case one would normally also call `make restart' to allow the
2472847Sgshapiro# running sendmail to pick up the changes as well.
2572847Sgshapiro#
2672847Sgshapiro# ------------------------------------------------------------------------
2772847Sgshapiro#
2876622Sgshapiro# This makefile uses `<HOSTNAME>.mc' as the default .mc file.  This can
2972847Sgshapiro# be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.:
3072847Sgshapiro#
3172847Sgshapiro#		   SENDMAIL_MC=/etc/mail/myconfig.mc
3272847Sgshapiro#
3376622Sgshapiro# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc'
3476622Sgshapiro# as a template.
3572847Sgshapiro# ------------------------------------------------------------------------
3672847Sgshapiro#
3772847Sgshapiro# The Makefile knows about the following maps:
3872847Sgshapiro# access, bitdomain, domaintable, genericstable, mailertable, userdb,
3972847Sgshapiro# uucpdomain, virtusertable
4072847Sgshapiro#
4139146Sbrian
4276622Sgshapiro.ifndef SENDMAIL_MC
4376622SgshapiroSENDMAIL_MC!=           hostname
4476622SgshapiroSENDMAIL_MC:=           ${SENDMAIL_MC}.mc
4576622Sgshapiro
4684684Sgshapiro${SENDMAIL_MC}:
4776622Sgshapiro	cp freebsd.mc ${SENDMAIL_MC}
4876622Sgshapiro.endif
4976622Sgshapiro
5073209SgshapiroINSTALL_CF=		${SENDMAIL_MC:R}.cf
5130581Sjmb
5272847SgshapiroSENDMAIL_ALIASES?=	/etc/mail/aliases
5357947Srwatson
5472847Sgshapiro#
5572847Sgshapiro# This is the directory where the sendmail configuration files are
5672847Sgshapiro# located.
5772847Sgshapiro#
5872847Sgshapiro.if exists(/usr/share/sendmail/cf)
5972847SgshapiroSENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
6072847Sgshapiro.elif exists(/usr/src/contrib/sendmail/cf)
6172847SgshapiroSENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
6272847Sgshapiro.endif
6357947Srwatson
6472847Sgshapiro#
6572847Sgshapiro# The pid is used to stop and restart the running daemon.
6672847Sgshapiro#
6772847SgshapiroSENDMAIL_PIDFILE?=	/var/run/sendmail.pid
6857947Srwatson
6972847Sgshapiro#
7072847Sgshapiro# Some useful programs we need.
7172847Sgshapiro#
7272847SgshapiroSENDMAIL?=		/usr/sbin/sendmail
7372847SgshapiroMAKEMAP?=		/usr/sbin/makemap
7472847SgshapiroM4?=			/usr/bin/m4
7572847SgshapiroKILL?=			/bin/kill
7664567Sgshapiro
7772847Sgshapiro# Set a reasonable default
7872847Sgshapiro.MAIN:	all
7957947Srwatson
8072847Sgshapiro#
8172847Sgshapiro# ------------------------------------------------------------------------
8272847Sgshapiro#
8372847Sgshapiro# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
8472847Sgshapiro# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
8575074Sgshapiro# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
8675074Sgshapiro# type to use when calling makemap.
8772847Sgshapiro#
8872847SgshapiroSENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
8975073Sgshapiro			genericstable virtusertable access
9072847SgshapiroSENDMAIL_MAP_OBJ=
9175074SgshapiroSENDMAIL_MAP_TYPE?=	hash
9257947Srwatson
9375073Sgshapiro.for _f in ${SENDMAIL_MAP_SRC} userdb
9472847Sgshapiro.if exists(${_f})
9572847SgshapiroSENDMAIL_MAP_OBJ+=	${_f}.db
9672847Sgshapiro.endif
9772847Sgshapiro.endfor
9857947Srwatson
9972847Sgshapiro#
10072847Sgshapiro# The makemap command is used to generate a hashed map from the textfile.
10172847Sgshapiro#
10272847Sgshapiro.for _f in ${SENDMAIL_MAP_SRC}
10372847Sgshapiro.if (exists(${_f}.sample) && !exists(${_f}))
10472847Sgshapiro${_f}:		${_f}.sample
10572847Sgshapiro	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
10672847Sgshapiro.endif
10772847Sgshapiro
10872847Sgshapiro${_f}.db:	${_f}
10975074Sgshapiro	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
11072847Sgshapiro.endfor
11172847Sgshapiro
11275073Sgshapirouserdb.db:	userdb
11375073Sgshapiro	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
11475073Sgshapiro
11575073Sgshapiro
11672847Sgshapiro#
11772847Sgshapiro# The .cf file needs to be recreated if the templates were modified.
11872847Sgshapiro#
11972847SgshapiroM4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
12072847Sgshapiro
12172847Sgshapiro#
12272847Sgshapiro# M4(1) is used to generate the .cf file from the .mc file.
12372847Sgshapiro#
12472847Sgshapiro.SUFFIXES:	.cf .mc
12572847Sgshapiro
12672847Sgshapiro.mc.cf:		${M4FILES}
12780175Sgshapiro	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
12880175Sgshapiro		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
12972847Sgshapiro
13072847Sgshapiro#
13172847Sgshapiro# Aliases are handled separately since they normally reside in /etc
13272847Sgshapiro# and can be rebuild without the help of makemap.
13372847Sgshapiro#
13472847Sgshapiro${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
13572847Sgshapiro	${SENDMAIL} -bi
13672847Sgshapiro
13772847Sgshapiro#
13872847Sgshapiro# ------------------------------------------------------------------------
13972847Sgshapiro#
14072847Sgshapiro
14172847Sgshapiroall:		cf maps aliases
14272847Sgshapiro
14357947Srwatsonclean:
14472847Sgshapiro
14572847Sgshapirodepend:
14672847Sgshapiro
14773209Sgshapirocf:		${INSTALL_CF}
14872847Sgshapiro
14990806Sgshapirosubmit.cf:	submit.mc
15090806Sgshapiro.ifdef SENDMAIL_SET_USER_ID
15190806Sgshapiro	@echo ">>> ERROR: You should not create a submit.cf file if you are using a"
15290806Sgshapiro	@echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
15390806Sgshapiro	@echo "           in make.conf)."
15490806Sgshapiro	@false
15590806Sgshapiro.endif
15690806Sgshapiro
15772847Sgshapiromaps:		${SENDMAIL_MAP_OBJ}
15872847Sgshapiro
15972847Sgshapiroaliases:	${SENDMAIL_ALIASES}.db
16072847Sgshapiro
16173209Sgshapiroinstall:	${INSTALL_CF}
16280176Sgshapiro.if ${INSTALL_CF} != /etc/mail/sendmail.cf
16373209Sgshapiro	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
16480176Sgshapiro.endif
16572847Sgshapiro
16672847Sgshapirostart:
16774218Sgshapiro	(. /etc/defaults/rc.conf; source_rc_confs; \
16886638Sgshapiro	case "$${sendmail_enable}" in \
16986638Sgshapiro	[Yy][Ee][Ss]) \
17086638Sgshapiro		/usr/sbin/sendmail $${sendmail_flags} \
17186638Sgshapiro		;; \
17286638Sgshapiro	*) \
17386638Sgshapiro		case "$${sendmail_outbound_enable}" in \
17486638Sgshapiro		[Yy][Ee][Ss]) \
17586638Sgshapiro			/usr/sbin/sendmail $${sendmail_outbound_flags} \
17686638Sgshapiro			;; \
17786638Sgshapiro		esac \
17886638Sgshapiro		;; \
17986638Sgshapiro	esac \
18072847Sgshapiro	)
18172847Sgshapiro
18272847Sgshapirostop:
18372847Sgshapiro	${KILL} -TERM `head -1 ${SENDMAIL_PIDFILE}`
18472847Sgshapiro
18572847Sgshapirorestart:
18672847Sgshapiro	${KILL} -HUP `head -1 ${SENDMAIL_PIDFILE}`
18776623Sgshapiro
18876623Sgshapiro# User defined targets
18976623Sgshapiro.if exists(Makefile.local)
19076623Sgshapiro.include "Makefile.local"
19176623Sgshapiro.endif
192