Makefile revision 76623
172847Sgshapiro#
250472Speter# $FreeBSD: head/etc/mail/Makefile 76623 2001-05-15 16:03:54Z 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
4676622Sgshapiro${SENDMAIL_MC}: freebsd.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}
12772847Sgshapiro	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_CF_DIR}/m4/cf.m4 \
12872847Sgshapiro		${@: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
14972847Sgshapiromaps:		${SENDMAIL_MAP_OBJ}
15072847Sgshapiro
15172847Sgshapiroaliases:	${SENDMAIL_ALIASES}.db
15272847Sgshapiro
15373209Sgshapiroinstall:	${INSTALL_CF}
15473209Sgshapiro	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
15572847Sgshapiro
15672847Sgshapirostart:
15774218Sgshapiro	(. /etc/defaults/rc.conf; source_rc_confs; \
15872847Sgshapiro	   if [ "$${sendmail_enable}" = "YES" -a -r /etc/mail/sendmail.cf ];\
15972847Sgshapiro	   then \
16072847Sgshapiro	     ${SENDMAIL} $${sendmail_flags}; \
16172847Sgshapiro	   fi \
16272847Sgshapiro	)
16372847Sgshapiro
16472847Sgshapirostop:
16572847Sgshapiro	${KILL} -TERM `head -1 ${SENDMAIL_PIDFILE}`
16672847Sgshapiro
16772847Sgshapirorestart:
16872847Sgshapiro	${KILL} -HUP `head -1 ${SENDMAIL_PIDFILE}`
16976623Sgshapiro
17076623Sgshapiro# User defined targets
17176623Sgshapiro.if exists(Makefile.local)
17276623Sgshapiro.include "Makefile.local"
17376623Sgshapiro.endif
174