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