xref: /freebsd/etc/mail/Makefile (revision ce4946daa5ce852d28008dac492029500ab2ee95)
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# 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 `freebsd.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# ------------------------------------------------------------------------
34#
35# The Makefile knows about the following maps:
36# access, bitdomain, domaintable, genericstable, mailertable, userdb,
37# uucpdomain, virtusertable
38#
39
40SENDMAIL_MC?=		freebsd.mc
41INSTALL_CF=		${SENDMAIL_MC:R}.cf
42
43SENDMAIL_ALIASES?=	/etc/mail/aliases
44
45#
46# This is the directory where the sendmail configuration files are
47# located.
48#
49.if exists(/usr/share/sendmail/cf)
50SENDMAIL_CF_DIR?=	/usr/share/sendmail/cf
51.elif exists(/usr/src/contrib/sendmail/cf)
52SENDMAIL_CF_DIR?=	/usr/src/contrib/sendmail/cf
53.endif
54
55#
56# The pid is used to stop and restart the running daemon.
57#
58SENDMAIL_PIDFILE?=	/var/run/sendmail.pid
59
60#
61# Some useful programs we need.
62#
63SENDMAIL?=		/usr/sbin/sendmail
64MAKEMAP?=		/usr/sbin/makemap
65M4?=			/usr/bin/m4
66KILL?=			/bin/kill
67
68# Set a reasonable default
69.MAIN:	all
70
71#
72# ------------------------------------------------------------------------
73#
74# The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
75# stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
76# exists in the current directory.  SENDMAIL_MAP_TYPE is the database
77# type to use when calling makemap.
78#
79SENDMAIL_MAP_SRC+=	mailertable domaintable bitdomain uucpdomain \
80			genericstable virtusertable access
81SENDMAIL_MAP_OBJ=
82SENDMAIL_MAP_TYPE?=	hash
83
84.for _f in ${SENDMAIL_MAP_SRC} userdb
85.if exists(${_f})
86SENDMAIL_MAP_OBJ+=	${_f}.db
87.endif
88.endfor
89
90#
91# The makemap command is used to generate a hashed map from the textfile.
92#
93.for _f in ${SENDMAIL_MAP_SRC}
94.if (exists(${_f}.sample) && !exists(${_f}))
95${_f}:		${_f}.sample
96	sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
97.endif
98
99${_f}.db:	${_f}
100	${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
101.endfor
102
103userdb.db:	userdb
104	${MAKEMAP} btree ${.TARGET} < ${.OODATE}
105
106
107#
108# The .cf file needs to be recreated if the templates were modified.
109#
110M4FILES!=	find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
111
112#
113# M4(1) is used to generate the .cf file from the .mc file.
114#
115.SUFFIXES:	.cf .mc
116
117.mc.cf:		${M4FILES}
118	${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_CF_DIR}/m4/cf.m4 \
119		${@:R}.mc > ${.TARGET}
120
121#
122# Aliases are handled separately since they normally reside in /etc
123# and can be rebuild without the help of makemap.
124#
125${SENDMAIL_ALIASES}.db:	${SENDMAIL_ALIASES}
126	${SENDMAIL} -bi
127
128#
129# ------------------------------------------------------------------------
130#
131
132all:		cf maps aliases
133
134clean:
135
136depend:
137
138cf:		${INSTALL_CF}
139
140maps:		${SENDMAIL_MAP_OBJ}
141
142aliases:	${SENDMAIL_ALIASES}.db
143
144install:	${INSTALL_CF}
145	${INSTALL} -c -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
146
147start:
148	(. /etc/defaults/rc.conf; source_rc_confs; \
149	   if [ "$${sendmail_enable}" = "YES" -a -r /etc/mail/sendmail.cf ];\
150	   then \
151	     ${SENDMAIL} $${sendmail_flags}; \
152	   fi \
153	)
154
155stop:
156	${KILL} -TERM `head -1 ${SENDMAIL_PIDFILE}`
157
158restart:
159	${KILL} -HUP `head -1 ${SENDMAIL_PIDFILE}`
160