1# 2# $FreeBSD$ 3# 4# This Makefile provides an easy way to generate the configuration 5# file and database maps for the sendmail(8) daemon. 6# 7# The user-driven targets are: 8# 9# all - Build cf, maps and aliases 10# cf - Build the .cf file from .mc file 11# maps - Build the feature maps 12# aliases - Build the sendmail aliases 13# install - Install the .cf file as /etc/mail/sendmail.cf 14# 15# For the MTA daemon: 16# start - Start the sendmail daemon with the flags defined in 17# /etc/defaults/rc.conf or /etc/rc.conf 18# stop - Stop the sendmail daemon 19# restart - Restart the sendmail daemon 20# 21# For the MSP queue running daemon: 22# start-mspq - Start the sendmail MSP queue running daemon with the 23# flags defined in /etc/defaults/rc.conf or /etc/rc.conf 24# stop-mspq - Stop the sendmail MSP queue running daemon 25# restart-mspq - Restart the sendmail MSP queue running daemon 26# 27# Calling `make' will generate the updated versions when either the 28# aliases or one of the map files were changed. 29# 30# A `make install` is only necessary after modifying the .mc file. In 31# this case one would normally also call `make restart' to allow the 32# running sendmail to pick up the changes as well. 33# 34# ------------------------------------------------------------------------ 35# 36# This makefile uses `<HOSTNAME>.mc' as the default .mc file. This can 37# be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.: 38# 39# SENDMAIL_MC=/etc/mail/myconfig.mc 40# 41# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc' 42# as a template. 43# ------------------------------------------------------------------------ 44# 45# The Makefile knows about the following maps: 46# access, bitdomain, domaintable, genericstable, mailertable, userdb, 47# uucpdomain, virtusertable 48# 49 50.ifndef SENDMAIL_MC 51SENDMAIL_MC!= hostname 52SENDMAIL_MC:= ${SENDMAIL_MC}.mc 53 54${SENDMAIL_MC}: 55 cp freebsd.mc ${SENDMAIL_MC} 56.endif 57 58INSTALL_CF= ${SENDMAIL_MC:R}.cf 59 60SENDMAIL_ALIASES?= /etc/mail/aliases 61 62# 63# This is the directory where the sendmail configuration files are 64# located. 65# 66.if exists(/usr/share/sendmail/cf) 67SENDMAIL_CF_DIR?= /usr/share/sendmail/cf 68.elif exists(${.CURDIR}/../../contrib/sendmail/cf) 69SENDMAIL_CF_DIR?= ${.CURDIR}/../../contrib/sendmail/cf 70.endif 71 72# 73# The pid is used to stop and restart the running daemon. 74# 75SENDMAIL_PIDFILE?= /var/run/sendmail.pid 76SENDMAIL_MSPQ_PIDFILE?= /var/spool/clientmqueue/sm-client.pid 77 78# 79# Some useful programs we need. 80# 81SENDMAIL?= /usr/sbin/sendmail 82MAKEMAP?= /usr/sbin/makemap 83M4?= /usr/bin/m4 84KILL?= /bin/kill 85 86# Set a reasonable default 87.MAIN: all 88 89# 90# ------------------------------------------------------------------------ 91# 92# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and 93# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file 94# exists in the current directory. SENDMAIL_MAP_TYPE is the database 95# type to use when calling makemap. 96# 97SENDMAIL_MAP_SRC+= mailertable domaintable bitdomain uucpdomain \ 98 genericstable virtusertable access 99SENDMAIL_MAP_OBJ= 100SENDMAIL_MAP_TYPE?= hash 101 102.for _f in ${SENDMAIL_MAP_SRC} userdb 103.if exists(${_f}) 104SENDMAIL_MAP_OBJ+= ${_f}.db 105.endif 106.endfor 107 108# 109# The makemap command is used to generate a hashed map from the textfile. 110# 111.for _f in ${SENDMAIL_MAP_SRC} 112.if (exists(${_f}.sample) && !exists(${_f})) 113${_f}: ${_f}.sample 114 sed -e 's/^/#/' < ${.OODATE} > ${.TARGET} 115.endif 116 117${_f}.db: ${_f} 118 ${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE} 119.endfor 120 121userdb.db: userdb 122 ${MAKEMAP} btree ${.TARGET} < ${.OODATE} 123 124 125# 126# The .cf file needs to be recreated if the templates were modified. 127# 128M4FILES!= find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print 129 130# 131# M4(1) is used to generate the .cf file from the .mc file. 132# 133.SUFFIXES: .cf .mc 134 135.mc.cf: ${M4FILES} 136 ${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \ 137 ${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET} 138 139# 140# Aliases are handled separately since they normally reside in /etc 141# and can be rebuild without the help of makemap. 142# 143${SENDMAIL_ALIASES}.db: ${SENDMAIL_ALIASES} 144 ${SENDMAIL} -bi 145 146# 147# ------------------------------------------------------------------------ 148# 149 150all: cf maps aliases 151 152clean: 153 154depend: 155 156cf: ${INSTALL_CF} 157 158submit.cf: submit.mc 159.ifdef SENDMAIL_SET_USER_ID 160 @echo ">>> ERROR: You should not create a submit.cf file if you are using a" 161 @echo " set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set" 162 @echo " in make.conf)." 163 @false 164.endif 165 166maps: ${SENDMAIL_MAP_OBJ} 167 168aliases: ${SENDMAIL_ALIASES}.db 169 170install: ${INSTALL_CF} 171.if ${INSTALL_CF} != /etc/mail/sendmail.cf 172 ${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf 173.endif 174 175start: 176 @(. /etc/defaults/rc.conf; source_rc_confs; \ 177 case "$${sendmail_enable}" in \ 178 [Nn][Oo][Nn][Ee]) \ 179 echo "ERROR: sendmail_enable is set to $${sendmail_enable}" \ 180 ;; \ 181 [Yy][Ee][Ss]) \ 182 ${SENDMAIL} $${sendmail_flags}; \ 183 echo "${SENDMAIL} $${sendmail_flags}" \ 184 ;; \ 185 *) \ 186 case "$${sendmail_submit_enable}" in \ 187 [Yy][Ee][Ss]) \ 188 ${SENDMAIL} $${sendmail_submit_flags}; \ 189 echo "${SENDMAIL} $${sendmail_submit_flags}" \ 190 ;; \ 191 *) \ 192 case "$${sendmail_outbound_enable}" in \ 193 [Yy][Ee][Ss]) \ 194 ${SENDMAIL} $${sendmail_outbound_flags}; \ 195 echo "${SENDMAIL} $${sendmail_outbound_flags}" \ 196 ;; \ 197 esac \ 198 ;; \ 199 esac \ 200 ;; \ 201 esac \ 202 ) 203 204stop: 205 ${KILL} -TERM `head -1 ${SENDMAIL_PIDFILE}` 206 207restart: 208 ${KILL} -HUP `head -1 ${SENDMAIL_PIDFILE}` 209 210start-mspq: 211 @(. /etc/defaults/rc.conf; source_rc_confs; \ 212 case "$${sendmail_enable}" in \ 213 [Nn][Oo][Nn][Ee]) \ 214 echo "ERROR: sendmail_enable is set to $${sendmail_enable}" \ 215 ;; \ 216 *) \ 217 if [ -r /etc/mail/submit.cf ]; then \ 218 case "$${sendmail_msp_queue_enable}" in \ 219 [Yy][Ee][Ss]) \ 220 ${SENDMAIL} $${sendmail_msp_queue_flags}; \ 221 echo "${SENDMAIL} $${sendmail_msp_queue_flags}" \ 222 ;; \ 223 esac \ 224 fi \ 225 ;; \ 226 esac \ 227 ) 228 229stop-mspq: 230 ${KILL} -TERM `head -1 ${SENDMAIL_MSPQ_PIDFILE}` 231 232restart-mspq: 233 ${KILL} -HUP `head -1 ${SENDMAIL_MSPQ_PIDFILE}` 234 235# User defined targets 236.if exists(Makefile.local) 237.include "Makefile.local" 238.endif 239