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