Makefile revision 93853
1#
2# $FreeBSD: head/etc/mail/Makefile 93853 2002-04-05 02:30:49Z gshapiro $
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#
45# This makefile uses `<HOSTNAME>.mc' as the default .mc file.  This can
46# be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.:
47#
48#		   SENDMAIL_MC=/etc/mail/myconfig.mc
49#
50# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc'
51# as a template.
52# ------------------------------------------------------------------------
53#
54# The Makefile knows about the following maps:
55# access, bitdomain, domaintable, genericstable, mailertable, userdb,
56# uucpdomain, virtusertable
57#
58
59.ifndef SENDMAIL_MC
60SENDMAIL_MC!=           hostname
61SENDMAIL_MC:=           ${SENDMAIL_MC}.mc
62
63${SENDMAIL_MC}:
64	cp freebsd.mc ${SENDMAIL_MC}
65.endif
66
67INSTALL_CF=		${SENDMAIL_MC:R}.cf
68
69SENDMAIL_ALIASES?=	/etc/mail/aliases
70
71#
72# This is the directory where the sendmail configuration files are
73# located.
74#
75.if exists(/usr/share/sendmail/cf)
76SENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
77.elif exists(/usr/src/contrib/sendmail/cf)
78SENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
79.endif
80
81#
82# The sendmail startup script
83#
84SENDMAIL_START_SCRIPT?=	/etc/rc.sendmail
85
86#
87# Some useful programs we need.
88#
89SENDMAIL?=		/usr/sbin/sendmail
90MAKEMAP?=		/usr/sbin/makemap
91M4?=			/usr/bin/m4
92
93# Set a reasonable default
94.MAIN:	all
95
96#
97# ------------------------------------------------------------------------
98#
99# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
100# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
101# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
102# type to use when calling makemap.
103#
104SENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
105			genericstable virtusertable access
106SENDMAIL_MAP_OBJ=
107SENDMAIL_MAP_TYPE?=	hash
108
109.for _f in ${SENDMAIL_MAP_SRC} userdb
110.if exists(${_f})
111SENDMAIL_MAP_OBJ+=	${_f}.db
112.endif
113.endfor
114
115#
116# The makemap command is used to generate a hashed map from the textfile.
117#
118.for _f in ${SENDMAIL_MAP_SRC}
119.if (exists(${_f}.sample) && !exists(${_f}))
120${_f}:		${_f}.sample
121	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
122.endif
123
124${_f}.db:	${_f}
125	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
126.endfor
127
128userdb.db:	userdb
129	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
130
131
132#
133# The .cf file needs to be recreated if the templates were modified.
134#
135M4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
136
137#
138# M4(1) is used to generate the .cf file from the .mc file.
139#
140.SUFFIXES:	.cf .mc
141
142.mc.cf:		${M4FILES}
143	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
144		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
145
146#
147# Aliases are handled separately since they normally reside in /etc
148# and can be rebuild without the help of makemap.
149#
150${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
151	${SENDMAIL} -bi
152
153#
154# ------------------------------------------------------------------------
155#
156
157all:		cf maps aliases
158
159clean:
160
161depend:
162
163cf:		${INSTALL_CF}
164
165submit.cf:	submit.mc
166.ifdef SENDMAIL_SET_USER_ID
167	@echo ">>> ERROR: You should not create a submit.cf file if you are using a"
168	@echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
169	@echo "           in make.conf)."
170	@false
171.endif
172
173maps:		${SENDMAIL_MAP_OBJ}
174
175aliases:	${SENDMAIL_ALIASES}.db
176
177install:	${INSTALL_CF}
178.if ${INSTALL_CF} != /etc/mail/sendmail.cf
179	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
180.endif
181
182start start-mta start-mspq:
183	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
184		echo -n 'Starting:'; \
185		sh ${SENDMAIL_START_SCRIPT} $@; \
186		echo '.'; \
187	fi
188
189stop stop-mta stop-mspq:
190	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
191		echo -n 'Stopping:'; \
192		sh ${SENDMAIL_START_SCRIPT} $@; \
193		echo '.'; \
194	fi
195
196restart restart-mta restart-mspq:
197	@if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
198		echo -n 'Restarting:'; \
199		sh ${SENDMAIL_START_SCRIPT} $@; \
200		echo '.'; \
201	fi
202
203# User defined targets
204.if exists(Makefile.local)
205.include "Makefile.local"
206.endif
207