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