c65c47204df48630ee0f07cac277682399fa6e67
[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 # $DragonFly: src/etc/mail/Makefile,v 1.3 2005/07/25 00:24:31 gshapiro Exp $
4 #
5 # This Makefile provides an easy way to generate the configuration
6 # file and database maps for the sendmail(8) daemon.
7 #
8 # The user-driven targets are:
9 #
10 # all     - Build cf, maps and aliases
11 # cf      - Build the .cf file from .mc file
12 # maps    - Build the feature maps
13 # aliases - Build the sendmail aliases
14 # install - Install the .cf file as /etc/mail/sendmail.cf
15 #
16 # For acting on both the MTA daemon and MSP queue running daemon:
17 # start        - Start both the sendmail MTA daemon and MSP queue running
18 #                daemon with the flags defined in /etc/defaults/rc.conf or
19 #                /etc/rc.conf
20 # stop         - Stop both the sendmail MTA daemon and MSP queue running
21 #                daemon
22 # restart      - Restart both the sendmail MTA daemon and MSP queue running
23 #                daemon
24 #
25 # For acting on just the MTA daemon:
26 # start-mta    - Start the sendmail MTA daemon with the flags defined in
27 #                /etc/defaults/rc.conf or /etc/rc.conf
28 # stop-mta     - Stop the sendmail MTA daemon
29 # restart-mta  - Restart the sendmail MTA daemon
30 #
31 # For acting on just the MSP queue running daemon:
32 # start-mspq   - Start the sendmail MSP queue running daemon with the
33 #                flags defined in /etc/defaults/rc.conf or /etc/rc.conf
34 # stop-mspq    - Stop the sendmail MSP queue running daemon
35 # restart-mspq - Restart the sendmail MSP queue running daemon
36 #
37 # Calling `make' will generate the updated versions when either the
38 # aliases or one of the map files were changed.
39 #
40 # A `make install` is only necessary after modifying the .mc file. In
41 # this case one would normally also call `make restart' to allow the
42 # running sendmail to pick up the changes as well.
43 #
44 # ------------------------------------------------------------------------
45 # This Makefile uses `<HOSTNAME>.mc' as the default MTA .mc file.  This
46 # can 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 'dragonfly.mc'
51 # as a template.
52 #
53 # It also uses '<HOSTNAME>.submit.mc' as the default mail submission .mc
54 # file. This can be changed by defining SENDMAIL_SUBMIT_MC in
55 # /etc/make.conf, e.g.:
56 #
57 #                  SENDMAIL_SUBMIT_MC=/etc/mail/mysubmit.mc
58 #
59 # If '<HOSTNAME>.submit.mc' does not exist, it is created using
60 # 'dragonfly.submit.mc' as a template.
61 # ------------------------------------------------------------------------
62 #
63 # The Makefile knows about the following maps:
64 # access, bitdomain, domaintable, genericstable, mailertable, userdb,
65 # uucpdomain, virtusertable
66 #
67
68 .ifndef SENDMAIL_MC
69 SENDMAIL_MC!=           hostname
70 SENDMAIL_MC:=           ${SENDMAIL_MC}.mc
71
72 ${SENDMAIL_MC}:
73         cp dragonfly.mc ${SENDMAIL_MC}
74 .endif
75
76 .ifndef SENDMAIL_SUBMIT_MC
77 SENDMAIL_SUBMIT_MC!=    hostname
78 SENDMAIL_SUBMIT_MC:=    ${SENDMAIL_SUBMIT_MC}.submit.mc
79
80 ${SENDMAIL_SUBMIT_MC}:
81         cp dragonfly.submit.mc ${SENDMAIL_SUBMIT_MC}
82 .endif
83
84 INSTALL_CF=             ${SENDMAIL_MC:R}.cf
85
86 .ifndef SENDMAIL_SET_USER_ID
87 INSTALL_SUBMIT_CF=      ${SENDMAIL_SUBMIT_MC:R}.cf
88 .endif
89
90 SENDMAIL_ALIASES?=      /etc/mail/aliases
91
92 #
93 # This is the directory where the sendmail configuration files are
94 # located.
95 #
96 .if exists(/usr/share/sendmail/cf)
97 SENDMAIL_CF_DIR?=       /usr/share/sendmail/cf
98 .elif exists(/usr/src/contrib/sendmail/cf)
99 SENDMAIL_CF_DIR?=       /usr/src/contrib/sendmail/cf
100 .endif
101
102 #
103 # The sendmail startup script
104 #
105 SENDMAIL_START_SCRIPT?= /etc/rc.sendmail
106
107 #
108 # Some useful programs we need.
109 #
110 SENDMAIL?=              /usr/sbin/sendmail
111 MAKEMAP?=               /usr/sbin/makemap
112 M4?=                    /usr/bin/m4
113
114 # Permissions for generated maps
115 SENDMAIL_MAP_PERMS?=    0640
116
117 # Set a reasonable default
118 .MAIN:  all
119
120 #
121 # ------------------------------------------------------------------------
122 #
123 # The Makefile picks up the list of files from SENDMAIL_MAP_SRC and
124 # stores the matching .db filenames in SENDMAIL_MAP_OBJ if the file
125 # exists in the current directory.  SENDMAIL_MAP_TYPE is the database
126 # type to use when calling makemap.
127 #
128 SENDMAIL_MAP_SRC+=      mailertable domaintable bitdomain uucpdomain \
129                         genericstable virtusertable access
130 SENDMAIL_MAP_OBJ=
131 SENDMAIL_MAP_TYPE?=     hash
132
133 .for _f in ${SENDMAIL_MAP_SRC} userdb
134 .if exists(${_f})
135 SENDMAIL_MAP_OBJ+=      ${_f}.db
136 .endif
137 .endfor
138
139 #
140 # The makemap command is used to generate a hashed map from the textfile.
141 #
142 .for _f in ${SENDMAIL_MAP_SRC}
143 .if (exists(${_f}.sample) && !exists(${_f}))
144 ${_f}:          ${_f}.sample
145         sed -e 's/^/#/' < ${.OODATE} > ${.TARGET}
146 .endif
147
148 ${_f}.db:       ${_f}
149         ${MAKEMAP} ${SENDMAIL_MAP_TYPE} ${.TARGET} < ${.OODATE}
150         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
151 .endfor
152
153 userdb.db:      userdb
154         ${MAKEMAP} btree ${.TARGET} < ${.OODATE}
155         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
156
157
158 #
159 # The .cf file needs to be recreated if the templates were modified.
160 #
161 M4FILES!=       find ${SENDMAIL_CF_DIR} -type f -name '*.m4' -print
162
163 #
164 # M4(1) is used to generate the .cf file from the .mc file.
165 #
166 .SUFFIXES:      .cf .mc
167
168 .mc.cf:         ${M4FILES}
169         ${M4} -D_CF_DIR_=${SENDMAIL_CF_DIR}/ ${SENDMAIL_M4_FLAGS} \
170                 ${SENDMAIL_CF_DIR}/m4/cf.m4 ${@:R}.mc > ${.TARGET}
171
172 #
173 # Aliases are handled separately since they normally reside in /etc
174 # and can be rebuild without the help of makemap.
175 #
176 .for _f in ${SENDMAIL_ALIASES}
177 ${_f}.db:       ${_f}
178         ${SENDMAIL} -bi -OAliasFile=${.ALLSRC}
179         chmod ${SENDMAIL_MAP_PERMS} ${.TARGET}
180 .endfor
181
182 #
183 # ------------------------------------------------------------------------
184 #
185
186 all:            cf maps aliases
187
188 clean:
189
190 depend:
191
192 cf:             ${INSTALL_CF} ${INSTALL_SUBMIT_CF}
193
194 .ifdef SENDMAIL_SET_USER_ID
195 install: install-cf
196 .else
197 install: install-cf install-submit-cf
198 .endif
199
200 install-cf:     ${INSTALL_CF}
201 .if ${INSTALL_CF} != /etc/mail/sendmail.cf
202         ${INSTALL} -m ${SHAREMODE} ${INSTALL_CF} /etc/mail/sendmail.cf
203 .endif
204
205
206 install-submit-cf:      ${INSTALL_SUBMIT_CF}
207 .ifdef SENDMAIL_SET_USER_ID
208         @echo ">>> ERROR: You should not create a submit.cf file if you are using a"
209         @echo "           set-user-ID sendmail binary (SENDMAIL_SET_USER_ID is set"
210         @echo "           in make.conf)."
211         @false
212 .else
213 .if ${INSTALL_SUBMIT_CF} != /etc/mail/submit.cf
214         ${INSTALL} -m ${SHAREMODE} ${INSTALL_SUBMIT_CF} /etc/mail/submit.cf
215 .endif
216 .endif
217
218 aliases:        ${SENDMAIL_ALIASES:%=%.db}
219
220 maps:           ${SENDMAIL_MAP_OBJ}
221
222 start start-mta start-mspq:
223         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
224                 echo -n 'Starting:'; \
225                 sh ${SENDMAIL_START_SCRIPT} $@; \
226                 echo '.'; \
227         fi
228
229 stop stop-mta stop-mspq:
230         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
231                 echo -n 'Stopping:'; \
232                 sh ${SENDMAIL_START_SCRIPT} $@; \
233                 echo '.'; \
234         fi
235
236 restart restart-mta restart-mspq:
237         @if [ -r ${SENDMAIL_START_SCRIPT} ]; then \
238                 echo -n 'Restarting:'; \
239                 sh ${SENDMAIL_START_SCRIPT} $@; \
240                 echo '.'; \
241         fi
242
243 # User defined targets
244 .if exists(Makefile.local)
245 .include "Makefile.local"
246 .endif
247
248 # For the definition of $SHAREMODE
249 .include <bsd.own.mk>