Merge remote-tracking branch 'remotes/anomaly256/389-ds-base'
[gentoo.git] / mail-mta / exim / exim-4.87_rc3.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="5"
6
7 inherit eutils toolchain-funcs multilib pam systemd
8
9 IUSE="dane dcc +dkim dlfunc dmarc +dnsdb doc dovecot-sasl dsn exiscan-acl gnutls ipv6 ldap libressl lmtp maildir mbx mysql nis pam perl pkcs11 postgres +prdr proxy radius redis sasl selinux spf sqlite srs ssl syslog tcpd tpda X"
10 REQUIRED_USE="spf? ( exiscan-acl ) srs? ( exiscan-acl ) dmarc? ( spf dkim ) pkcs11? ( gnutls )"
11
12 COMM_URI="ftp://ftp.exim.org/pub/exim/exim4$([[ ${PV} == *_rc* ]] && echo /test)"
13
14 DESCRIPTION="A highly configurable, drop-in replacement for sendmail"
15 SRC_URI="${COMM_URI}/${P//rc/RC}.tar.bz2
16         mirror://gentoo/system_filter.exim.gz
17         doc? ( ${COMM_URI}/${PN}-html-${PV//rc/RC}.tar.bz2 )"
18 HOMEPAGE="http://www.exim.org/"
19
20 SLOT="0"
21 LICENSE="GPL-2"
22 KEYWORDS="~amd64 ~hppa ~ppc64 ~x86"
23
24 COMMON_DEPEND=">=sys-apps/sed-4.0.5
25         >=sys-libs/db-3.2
26         dev-libs/libpcre
27         perl? ( dev-lang/perl:= )
28         pam? ( virtual/pam )
29         tcpd? ( sys-apps/tcp-wrappers )
30         ssl? (
31                 !libressl? ( dev-libs/openssl:0=[-bindist] )
32                 libressl? ( dev-libs/libressl:= )
33         )
34         gnutls? ( net-libs/gnutls[pkcs11?]
35                           dev-libs/libtasn1 )
36         ldap? ( >=net-nds/openldap-2.0.7 )
37         mysql? ( virtual/mysql )
38         postgres? ( dev-db/postgresql )
39         sasl? ( >=dev-libs/cyrus-sasl-2.1.26-r2 )
40         redis? ( dev-libs/hiredis )
41         spf? ( >=mail-filter/libspf2-1.2.5-r1 )
42         dmarc? ( mail-filter/opendmarc )
43         srs? ( mail-filter/libsrs_alt )
44         X? ( x11-proto/xproto
45                 x11-libs/libX11
46                 x11-libs/libXmu
47                 x11-libs/libXt
48                 x11-libs/libXaw
49         )
50         sqlite? ( dev-db/sqlite )
51         radius? ( net-dialup/freeradius-client )
52         virtual/libiconv
53         "
54         # added X check for #57206
55 DEPEND="${COMMON_DEPEND}
56         virtual/pkgconfig"
57 RDEPEND="${COMMON_DEPEND}
58         !mail-mta/courier
59         !mail-mta/esmtp
60         !mail-mta/mini-qmail
61         !<mail-mta/msmtp-1.4.19-r1
62         !>=mail-mta/msmtp-1.4.19-r1[mta]
63         !mail-mta/netqmail
64         !mail-mta/nullmailer
65         !mail-mta/postfix
66         !mail-mta/qmail-ldap
67         !mail-mta/sendmail
68         !mail-mta/opensmtpd
69         !<mail-mta/ssmtp-2.64-r2
70         !>=mail-mta/ssmtp-2.64-r2[mta]
71         !net-mail/mailwrapper
72         >=net-mail/mailbase-0.00-r5
73         virtual/logger
74         dcc? ( mail-filter/dcc )
75         selinux? ( sec-policy/selinux-exim )
76         "
77
78 S=${WORKDIR}/${P//rc/RC}
79
80 src_prepare() {
81         epatch "${FILESDIR}"/exim-4.14-tail.patch
82         epatch "${FILESDIR}"/exim-4.74-localscan_dlopen.patch
83         epatch "${FILESDIR}"/exim-4.69-r1.27021.patch
84         epatch "${FILESDIR}"/exim-4.74-radius-db-ENV-clash.patch # 287426
85         epatch "${FILESDIR}"/exim-4.82-makefile-freebsd.patch # 235785
86         epatch "${FILESDIR}"/exim-4.87-as-needed-ldflags.patch # 352265, 391279
87         epatch "${FILESDIR}"/exim-4.76-crosscompile.patch # 266591
88         epatch "${FILESDIR}"/exim-4.86-TMPDIR.patch # 63420
89
90         if use maildir ; then
91                 epatch "${FILESDIR}"/exim-4.20-maildir.patch
92         else
93                 epatch "${FILESDIR}"/exim-4.80-spool-mail-group.patch # 438606
94         fi
95
96         # user Exim believes it should be
97         MAILUSER=mail
98         MAILGROUP=mail
99         if use prefix && [[ ${EUID} != 0 ]] ; then
100                 MAILUSER=$(id -un)
101                 MAILGROUP=$(id -gn)
102         fi
103 }
104
105 src_configure() {
106         # general config and paths
107
108         sed -i.orig \
109                 -e "/SYSTEM_ALIASES_FILE/s'SYSTEM_ALIASES_FILE'${EPREFIX}/etc/mail/aliases'" \
110                 "${S}"/src/configure.default || die
111
112         sed -i -e 's/^buildname=.*/buildname=exim-gentoo/g' Makefile || die
113
114         sed -e "48i\CFLAGS=${CFLAGS}" \
115                 -e "s:BIN_DIRECTORY=/usr/exim/bin:BIN_DIRECTORY=${EPREFIX}/usr/sbin:" \
116                 -e "s:EXIM_USER=:EXIM_USER=${MAILUSER}:" \
117                 -e "s:CONFIGURE_FILE=/usr/exim/configure:CONFIGURE_FILE=${EPREFIX}/etc/exim/exim.conf:" \
118                 -e "s:ZCAT_COMMAND=.*$:ZCAT_COMMAND=${EPREFIX}/bin/zcat:" \
119                 -e "s:COMPRESS_COMMAND=.*$:COMPRESS_COMMAND=${EPREFIX}/bin/gzip:" \
120                 src/EDITME > Local/Makefile
121
122         cd Local
123
124         cat >> Makefile <<- EOC
125                 INFO_DIRECTORY=${EPREFIX}/usr/share/info
126                 PID_FILE_PATH=${EPREFIX}/run/exim.pid
127                 SPOOL_DIRECTORY=${EPREFIX}/var/spool/exim
128                 HAVE_ICONV=yes
129         EOC
130
131         # if we use libiconv, now is the time to tell so
132         use !elibc_glibc && echo "EXTRALIBS_EXIM=-liconv" >> Makefile
133
134         # support for IPv6
135         if use ipv6; then
136                 cat >> Makefile <<- EOC
137                         HAVE_IPV6=YES
138                 EOC
139         fi
140
141         #
142         # mail storage formats
143
144         # mailstore is Exim's traditional storage format
145         cat >> Makefile <<- EOC
146                 SUPPORT_MAILSTORE=yes
147         EOC
148
149         # mbox
150         if use mbx; then
151                 cat >> Makefile <<- EOC
152                         SUPPORT_MBX=yes
153                 EOC
154         fi
155
156         # maildir
157         if use maildir; then
158                 cat >> Makefile <<- EOC
159                         SUPPORT_MAILDIR=yes
160                 EOC
161         fi
162
163         #
164         # lookup methods
165
166         # use the "native" interfaces to the DBM and CDB libraries, support
167         # passwd and directory lookups by default
168         cat >> Makefile <<- EOC
169                 USE_DB=yes
170                 DBMLIB=-ldb
171                 LOOKUP_CDB=yes
172                 LOOKUP_PASSWD=yes
173                 LOOKUP_DSEARCH=yes
174         EOC
175
176         if ! use dnsdb; then
177                 # DNSDB lookup is enabled by default
178                 sed -i "s:^LOOKUP_DNSDB=yes:# LOOKUP_DNSDB=yes:" Makefile
179         fi
180
181         if use ldap; then
182                 cat >> Makefile <<- EOC
183                         LOOKUP_LDAP=yes
184                         LDAP_LIB_TYPE=OPENLDAP2
185                         LOOKUP_INCLUDE += -I"${EROOT}"usr/include/ldap
186                         LOOKUP_LIBS += -lldap -llber
187                 EOC
188         fi
189
190         if use mysql; then
191                 cat >> Makefile <<- EOC
192                         LOOKUP_MYSQL=yes
193                         LOOKUP_INCLUDE += $(mysql_config --include)
194                         LOOKUP_LIBS += $(mysql_config --libs)
195                 EOC
196         fi
197
198         if use nis; then
199                 cat >> Makefile <<- EOC
200                         LOOKUP_NIS=yes
201                         LOOKUP_NISPLUS=yes
202                 EOC
203         fi
204
205         if use postgres; then
206                 cat >> Makefile <<- EOC
207                         LOOKUP_PGSQL=yes
208                         LOOKUP_INCLUDE += -I$(pg_config --includedir)
209                         LOOKUP_LIBS += -L$(pg_config --libdir) -lpq
210                 EOC
211         fi
212
213         if use sqlite; then
214                 cat >> Makefile <<- EOC
215                         LOOKUP_SQLITE=yes
216                         LOOKUP_SQLITE_PC=sqlite3
217                 EOC
218         fi
219
220         if use redis; then
221                 cat >> Makefile <<- EOC
222                         EXPERIMENTAL_REDIS=yes
223                         LOOKUP_LIBS += -lhiredis
224                 EOC
225         fi
226
227         #
228         # Exim monitor, enabled by default, controlled via X USE-flag,
229         # disable if not requested, bug #46778
230         if use X; then
231                 cp ../exim_monitor/EDITME eximon.conf || die
232         else
233                 sed -i -e '/^EXIM_MONITOR=/s/^/# /' Makefile
234         fi
235
236         #
237         # features
238
239         # content scanning support
240         if use exiscan-acl; then
241                 cat >> Makefile <<- EOC
242                         WITH_CONTENT_SCAN=yes
243                         WITH_OLD_DEMIME=yes
244                 EOC
245         fi
246
247         # DomainKeys Identified Mail, RFC4871
248         if ! use dkim; then
249                 # DKIM is enabled by default
250                 cat >> Makefile <<- EOC
251                         DISABLE_DKIM=yes
252                 EOC
253         fi
254
255         # Per-Recipient-Data-Response
256         if ! use prdr; then
257                 # PRDR is enabled by default
258                 cat >> Makefile <<- EOC
259                         DISABLE_PRDR=yes
260                 EOC
261         fi
262
263         # log to syslog
264         if use syslog; then
265                 sed -i "s:LOG_FILE_PATH=/var/log/exim/exim_%s.log:LOG_FILE_PATH=syslog:" Makefile
266                 cat >> Makefile <<- EOC
267                         LOG_FILE_PATH=syslog
268                 EOC
269         else
270                 cat >> Makefile <<- EOC
271                         LOG_FILE_PATH=${EPREFIX}/var/log/exim/exim_%s.log
272                 EOC
273         fi
274
275         # starttls support (ssl)
276         if use ssl; then
277                 echo "SUPPORT_TLS=yes" >> Makefile
278                 if use gnutls; then
279                         echo "USE_GNUTLS=yes" >> Makefile
280                         echo "USE_GNUTLS_PC=gnutls" >> Makefile
281                         use pkcs11 || echo "AVOID_GNUTLS_PKCS11=yes" >> Makefile
282                 else
283                         echo "USE_OPENSSL_PC=openssl" >> Makefile
284                 fi
285         fi
286
287         # TCP wrappers
288         if use tcpd; then
289                 cat >> Makefile <<- EOC
290                         USE_TCP_WRAPPERS=yes
291                         EXTRALIBS_EXIM += -lwrap
292                 EOC
293         fi
294
295         # Light Mail Transport Protocol
296         if use lmtp; then
297                 cat >> Makefile <<- EOC
298                         TRANSPORT_LMTP=yes
299                 EOC
300         fi
301
302         # embedded Perl
303         if use perl; then
304                 cat >> Makefile <<- EOC
305                         EXIM_PERL=perl.o
306                 EOC
307         fi
308
309         # dlfunc
310         if use dlfunc; then
311                 cat >> Makefile <<- EOC
312                         EXPAND_DLFUNC=yes
313                 EOC
314         fi
315
316         #
317         # experimental features
318
319         # DANE
320         if use dane; then
321                 cat >> Makefile <<- EOC
322                         EXPERIMENTAL_DANE=yes
323                 EOC
324         fi
325
326         # Distributed Checksum Clearinghouse
327         if use dcc; then
328                 echo "EXPERIMENTAL_DCC=yes">> Makefile
329         fi
330
331         # Sender Policy Framework
332         if use spf; then
333                 cat >> Makefile <<- EOC
334                         EXPERIMENTAL_SPF=yes
335                         EXTRALIBS_EXIM += -lspf2
336                 EOC
337         fi
338
339         # Sender Rewriting Scheme
340         if use srs; then
341                 cat >> Makefile <<- EOC
342                         EXPERIMENTAL_SRS=yes
343                         EXTRALIBS_EXIM += -lsrs_alt
344                 EOC
345         fi
346
347         # DMARC
348         if use dmarc; then
349                 cat >> Makefile <<- EOC
350                         EXPERIMENTAL_DMARC=yes
351                         EXTRALIBS_EXIM += -lopendmarc
352                 EOC
353         fi
354
355         # Transport post-delivery actions
356         if use tpda; then
357                 cat >> Makefile <<- EOC
358                         EXPERIMENTAL_EVENT=yes
359                 EOC
360         fi
361
362         # Proxy Protocol
363         if use proxy; then
364                 cat >> Makefile <<- EOC
365                         EXPERIMENTAL_PROXY=yes
366                 EOC
367         fi
368
369         # Delivery Sender Notifications
370         if use dsn; then
371                 cat >> Makefile <<- EOC
372                         EXPERIMENTAL_DSN=yes
373                 EOC
374         fi
375
376         #
377         # authentication (SMTP AUTH)
378
379         # standard bits
380         cat >> Makefile <<- EOC
381                 AUTH_SPA=yes
382                 AUTH_CRAM_MD5=yes
383                 AUTH_PLAINTEXT=yes
384         EOC
385
386         # Cyrus SASL
387         if use sasl; then
388                 cat >> Makefile <<- EOC
389                         CYRUS_SASLAUTHD_SOCKET=${EPREFIX}/run/saslauthd/mux
390                         AUTH_CYRUS_SASL=yes
391                         AUTH_LIBS += -lsasl2
392                 EOC
393         fi
394
395         # Dovecot
396         if use dovecot-sasl; then
397                 cat >> Makefile <<- EOC
398                         AUTH_DOVECOT=yes
399                 EOC
400         fi
401
402         # Pluggable Authentication Modules
403         if use pam; then
404                 cat >> Makefile <<- EOC
405                         SUPPORT_PAM=yes
406                         AUTH_LIBS += -lpam
407                 EOC
408         fi
409
410         # Radius
411         if use radius; then
412                 cat >> Makefile <<- EOC
413                         RADIUS_CONFIG_FILE=${EPREFIX}/etc/radiusclient/radiusclient.conf
414                         RADIUS_LIB_TYPE=RADIUSCLIENTNEW
415                         AUTH_LIBS += -lfreeradius-client
416                 EOC
417         fi
418 }
419
420 src_compile() {
421         emake -j1 CC="$(tc-getCC)" HOSTCC="$(tc-getCC $CBUILD)" \
422                 AR="$(tc-getAR) cq" RANLIB="$(tc-getRANLIB)" FULLECHO='' \
423                 || die "make failed"
424 }
425
426 src_install () {
427         cd "${S}"/build-exim-gentoo || die
428         dosbin exim
429         if use X; then
430                 dosbin eximon.bin
431                 dosbin eximon
432         fi
433         fperms 4755 /usr/sbin/exim
434
435         dosym exim /usr/sbin/sendmail
436         dosym exim /usr/sbin/rsmtp
437         dosym exim /usr/sbin/rmail
438         dosym /usr/sbin/exim /usr/bin/mailq
439         dosym /usr/sbin/exim /usr/bin/newaliases
440         dosym /usr/sbin/sendmail /usr/lib/sendmail
441
442         for i in exicyclog exim_dbmbuild exim_dumpdb exim_fixdb exim_lock \
443                 exim_tidydb exinext exiwhat exigrep eximstats exiqsumm exiqgrep \
444                 convert4r3 convert4r4 exipick
445         do
446                 dosbin $i
447         done
448
449         dodoc "${S}"/doc/*
450         doman "${S}"/doc/exim.8
451         use dsn && dodoc "${S}"/README.DSN
452         use doc && dohtml -r "${WORKDIR}"/${PN}-html-${PV//rc/RC}/doc/html/spec_html/*
453
454         # conf files
455         insinto /etc/exim
456         newins "${S}"/src/configure.default exim.conf.dist
457         if use exiscan-acl; then
458                 newins "${S}"/src/configure.default exim.conf.exiscan-acl
459         fi
460         doins "${WORKDIR}"/system_filter.exim
461         doins "${FILESDIR}"/auth_conf.sub
462
463         pamd_mimic system-auth exim auth account
464
465         # headers, #436406
466         if use dlfunc ; then
467                 # fixup includes so they actually can be found when including
468                 sed -i \
469                         -e '/#include "\(config\|store\|mytypes\).h"/s:"\(.\+\)":<exim/\1>:' \
470                         local_scan.h || die
471                 insinto /usr/include/exim
472                 doins {config,local_scan}.h ../src/{mytypes,store}.h
473         fi
474
475         insinto /etc/logrotate.d
476         newins "${FILESDIR}/exim.logrotate" exim
477
478         newinitd "${FILESDIR}"/exim.rc9 exim
479         newconfd "${FILESDIR}"/exim.confd exim
480
481         systemd_dounit "${FILESDIR}"/{exim.service,exim.socket,exim-submission.socket}
482         systemd_newunit "${FILESDIR}"/exim_at.service 'exim@.service'
483         systemd_newunit "${FILESDIR}"/exim-submission_at.service 'exim-submission@.service'
484
485         diropts -m 0750 -o ${MAILUSER} -g ${MAILGROUP}
486         dodir /var/log/${PN}
487 }
488
489 pkg_postinst() {
490         if [[ ! -f ${EROOT}etc/exim/exim.conf ]] ; then
491                 einfo "${EROOT}etc/exim/system_filter.exim is a sample system_filter."
492                 einfo "${EROOT}etc/exim/auth_conf.sub contains the configuration sub for using smtp auth."
493                 einfo "Please create ${EROOT}etc/exim/exim.conf from ${EROOT}etc/exim/exim.conf.dist."
494         fi
495         use dane && einfo "DANE support is experimental"
496         if use dcc ; then
497                 einfo "DCC support is experimental, you can find some limited"
498                 einfo "documentation at the bottom of this prerelease message:"
499                 einfo "http://article.gmane.org/gmane.mail.exim.devel/3579"
500         fi
501         use spf && einfo "SPF support is experimental"
502         use srs && einfo "SRS support is experimental"
503         if use dmarc ; then
504                 einfo "DMARC support is experimental.  See global settings to"
505                 einfo "configure DMARC, for usage see the documentation at "
506                 einfo "experimental-spec.txt."
507         fi
508         use tpda && einfo "TPDA/EVENT support is experimental"
509         use proxy && einfo "proxy support is experimental"
510         if use dsn ; then
511                 einfo "Starting from Exim 4.83, DSN support comes from upstream."
512                 einfo "DSN support is an experimental feature.  If you used DSN"
513                 einfo "support prior to 4.83, make sure to remove all dsn_process"
514                 einfo "switches from your routers, see https://bugs.gentoo.org/511818"
515         fi
516         einfo "Exim maintains some db files under its spool directory that need"
517         einfo "cleaning from time to time.  (${EROOT}var/spool/exim/db)"
518         einfo "Please use the exim_tidydb tool as documented in the Exim manual:"
519         einfo "http://www.exim.org/exim-html-current/doc/html/spec_html/ch-exim_utilities.html#SECThindatmai"
520 }