Initial import from FreeBSD RELENG_4:
[dragonfly.git] / etc / mail / Makefile
1 #
2 # $FreeBSD: src/etc/mail/Makefile,v 1.9.2.23 2003/02/12 03:57:52 gshapiro Exp $
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
65 SENDMAIL_MC!=           hostname
66 SENDMAIL_MC:=           ${SENDMAIL_MC}.mc
67
68 ${SENDMAIL_MC}:
69         cp freebsd.mc ${SENDMAIL_MC}
70 .endif
71
72 SENDMAIL_SUBMIT_MC?=    freebsd.submit.mc
73
74 INSTALL_CF=             ${SENDMAIL_MC:R}.cf
75
76 .ifndef SENDMAIL_SET_USER_ID
77 INSTALL_SUBMIT_CF=      ${SENDMAIL_SUBMIT_MC:R}.cf
78 .endif
79
80 SENDMAIL_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)
87 SENDMAIL_CF_DIR?=       /usr/share/sendmail/cf
88 .elif exists(/usr/src/contrib/sendmail/cf)
89 SENDMAIL_CF_DIR?=       /usr/src/contrib/sendmail/cf
90 .endif
91
92 #
93 # The sendmail startup script
94 #
95 SENDMAIL_START_SCRIPT?= /etc/rc.sendmail
96
97 #
98 # Some useful programs we need.
99 #
100 SENDMAIL?=              /usr/sbin/sendmail
101 MAKEMAP?=               /usr/sbin/makemap
102 M4?=                    /usr/bin/m4
103
104 # Permissions for generated maps
105 SENDMAIL_MAP_PERMS?=    0640
106
107 # Set a reasonable default
108 .MAIN:  all
109
110 #
111 # ------------------------------------------------------------------------
112 #
113 # The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
114 # stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
115 # exists in the current directory.  SENDMAIL_MAP_TYPE is the database
116 # type to use when calling makemap.
117 #
118 SENDMAIL_MAP_SRC+=      mailertable domaintable bitdomain uucpdomain \
119                         genericstable virtusertable access
120 SENDMAIL_MAP_OBJ=
121 SENDMAIL_MAP_TYPE?=     hash
122
123 .for _f in ${SENDMAIL_MAP_SRC} userdb
124 .if exists(${_f})
125 SENDMAIL_MAP_OBJ+=      ${_f}.db
126 .endif
127 .endfor
128
129 #
130 # The makemap command is used to generate a hashed map from the textfile.
131 #
132 .for _f in ${SENDMAIL_MAP_SRC}
133 .if (exists(${_f}.sample) && !exists(${_f}))
134 ${_f}:          ${_f}.sample
135         sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
136 .endif
137
138 ${_f}.db:       ${_f}
139         ${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
140         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
141 .endfor
142
143 userdb.db:      userdb
144         ${MAKEMAP} btree ${.TARGET} < ${.OODATE}
145         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
146
147
148 #
149 # The .cf file needs to be recreated if the templates were modified.
150 #
151 M4FILES!=       find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
152
153 #
154 # M4(1) is used to generate the .cf file from the .mc file.
155 #
156 .SUFFIXES:      .cf .mc
157
158 .mc.cf:         ${M4FILES}
159         ${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
160                 ${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
161
162 #
163 # Aliases are handled separately since they normally reside in /etc
164 # and can be rebuild without the help of makemap.
165 #
166 .for _f in ${SENDMAIL_ALIASES}
167 ${_f}.db:       ${_f}
168         ${SENDMAIL} -bi -OAliasFile=${.ALLSRC}
169         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
170 .endfor
171
172 #
173 # ------------------------------------------------------------------------
174 #
175
176 all:            cf maps aliases
177
178 clean:
179
180 depend:
181
182 cf:             ${INSTALL_CF} ${INSTALL_SUBMIT_CF}
183
184 .ifdef SENDMAIL_SET_USER_ID
185 install: install-cf
186 .else
187 install: install-cf install-submit-cf
188 .endif
189
190 install-cf:     ${INSTALL_CF}
191 .if ${INSTALL_CF} != /etc/mail/sendmail.cf
192         ${INSTALL} -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
193 .endif
194
195
196 install-submit-cf:      ${INSTALL_SUBMIT_CF}
197 .ifdef SENDMAIL_SET_USER_ID
198         @echo ">>> ERROR: You should not create a submit.cf file if you are using a"
199         @echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
200         @echo "           in make.conf)."
201         @false
202 .else
203 .if ${INSTALL_SUBMIT_CF} != /etc/mail/submit.cf
204         ${INSTALL} -m ${SHAREMODE} ${INSTALL_SUBMIT_CF} /etc/mail/submit.cf
205 .endif
206 .endif
207
208 aliases:        ${SENDMAIL_ALIASES:%=%.db}
209
210 maps:           ${SENDMAIL_MAP_OBJ}
211
212 start start-mta start-mspq:
213         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
214                 echo -n 'Starting:'; \
215                 sh ${SENDMAIL_START_SCRIPT} $@; \
216                 echo '.'; \
217         fi
218
219 stop stop-mta stop-mspq:
220         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
221                 echo -n 'Stopping:'; \
222                 sh ${SENDMAIL_START_SCRIPT} $@; \
223                 echo '.'; \
224         fi
225
226 restart restart-mta restart-mspq:
227         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
228                 echo -n 'Restarting:'; \
229                 sh ${SENDMAIL_START_SCRIPT} $@; \
230                 echo '.'; \
231         fi
232
233 # User defined targets
234 .if exists(Makefile.local)
235 .include "Makefile.local"
236 .endif
237
238 # For the definition of $SHAREMODE
239 .include <bsd.own.mk>