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