Makefile revision 80176
1#
2# $FreeBSD: head/etc/mail/Makefile 80176 2001-07-23 02:19:02Z 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# start   - Start the sendmail daemon with the flags defined in
15#           /etc/defaults/rc.conf or /etc/rc.conf
16# stop    - Stop the sendmail daemon
17# restart - Restart the sendmail daemon
18#
19# Calling `make' will generate the updated versions when either the
20# aliases or one of the map files were changed.
21#
22# A `make install` is only necessary after modifying the .mc file. In
23# this case one would normally also call `make restart' to allow the
24# running sendmail to pick up the changes as well.
25#
26# ------------------------------------------------------------------------
27#
28# This makefile uses `<HOSTNAME>.mc' as the default .mc file.  This can
29# be changed by defining SENDMAIL_MC in /etc/make.conf, e.g.:
30#
31#		   SENDMAIL_MC=/etc/mail/myconfig.mc
32#
33# If '<HOSTNAME>.mc' does not exist, it is created using 'freebsd.mc'
34# as a template.
35# ------------------------------------------------------------------------
36#
37# The Makefile knows about the following maps:
38# access, bitdomain, domaintable, genericstable, mailertable, userdb,
39# uucpdomain, virtusertable
40#
41
42SENDMAIL_M4_FLAGS+=	-D_FFR_TLS_O_T
43
44.ifndef SENDMAIL_MC
45SENDMAIL_MC!=           hostname
46SENDMAIL_MC:=           ${SENDMAIL_MC}.mc
47
48${SENDMAIL_MC}: freebsd.mc
49	cp freebsd.mc ${SENDMAIL_MC}
50.endif
51
52INSTALL_CF=		${SENDMAIL_MC:R}.cf
53
54SENDMAIL_ALIASES?=	/etc/mail/aliases
55
56#
57# This is the directory where the sendmail configuration files are
58# located.
59#
60.if exists(/usr/share/sendmail/cf)
61SENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
62.elif exists(/usr/src/contrib/sendmail/cf)
63SENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
64.endif
65
66#
67# The pid is used to stop and restart the running daemon.
68#
69SENDMAIL_PIDFILE?=	/var/run/sendmail.pid
70
71#
72# Some useful programs we need.
73#
74SENDMAIL?=		/usr/sbin/sendmail
75MAKEMAP?=		/usr/sbin/makemap
76M4?=			/usr/bin/m4
77KILL?=			/bin/kill
78
79# Set a reasonable default
80.MAIN:	all
81
82#
83# ------------------------------------------------------------------------
84#
85# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
86# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
87# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
88# type to use when calling makemap.
89#
90SENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
91			genericstable virtusertable access
92SENDMAIL_MAP_OBJ=
93SENDMAIL_MAP_TYPE?=	hash
94
95.for _f in ${SENDMAIL_MAP_SRC} userdb
96.if exists(${_f})
97SENDMAIL_MAP_OBJ+=	${_f}.db
98.endif
99.endfor
100
101#
102# The makemap command is used to generate a hashed map from the textfile.
103#
104.for _f in ${SENDMAIL_MAP_SRC}
105.if (exists(${_f}.sample) && !exists(${_f}))
106${_f}:		${_f}.sample
107	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
108.endif
109
110${_f}.db:	${_f}
111	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
112.endfor
113
114userdb.db:	userdb
115	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
116
117
118#
119# The .cf file needs to be recreated if the templates were modified.
120#
121M4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
122
123#
124# M4(1) is used to generate the .cf file from the .mc file.
125#
126.SUFFIXES:	.cf .mc
127
128.mc.cf:		${M4FILES}
129	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
130		${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
131
132#
133# Aliases are handled separately since they normally reside in /etc
134# and can be rebuild without the help of makemap.
135#
136${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
137	${SENDMAIL} -bi
138
139#
140# ------------------------------------------------------------------------
141#
142
143all:		cf maps aliases
144
145clean:
146
147depend:
148
149cf:		${INSTALL_CF}
150
151maps:		${SENDMAIL_MAP_OBJ}
152
153aliases:	${SENDMAIL_ALIASES}.db
154
155install:	${INSTALL_CF}
156.if ${INSTALL_CF} != /etc/mail/sendmail.cf
157	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
158.endif
159
160start:
161	(. /etc/defaults/rc.conf; source_rc_confs; \
162	   if [ "$${sendmail_enable}" = "YES" -a -r /etc/mail/sendmail.cf ];\
163	   then \
164	     ${SENDMAIL} $${sendmail_flags}; \
165	   fi \
166	)
167
168stop:
169	${KILL} -TERM `head -1 ${SENDMAIL_PIDFILE}`
170
171restart:
172	${KILL} -HUP `head -1 ${SENDMAIL_PIDFILE}`
173
174# User defined targets
175.if exists(Makefile.local)
176.include "Makefile.local"
177.endif
178