f5698ffaf50ce7811f0da358ab2b9ad3aa9b732b
[gentoo.git] / mail-mta / postfix / postfix-3.4.7.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit flag-o-matic pam systemd toolchain-funcs
7
8 MY_PV="${PV/_rc/-RC}"
9 MY_SRC="${PN}-${MY_PV}"
10 MY_URI="ftp://ftp.porcupine.org/mirrors/postfix-release/official"
11 RC_VER="2.7"
12
13 DESCRIPTION="A fast and secure drop-in replacement for sendmail"
14 HOMEPAGE="http://www.postfix.org/"
15 SRC_URI="${MY_URI}/${MY_SRC}.tar.gz"
16
17 LICENSE="|| ( IBM EPL-2.0 )"
18 SLOT="0"
19 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~sh ~sparc ~x86"
20 IUSE="+berkdb cdb dovecot-sasl +eai hardened ldap ldap-bind libressl lmdb memcached mbox mysql nis pam postgres sasl selinux sqlite ssl"
21
22 DEPEND=">=dev-libs/libpcre-3.4
23         dev-lang/perl
24         berkdb? ( >=sys-libs/db-3.2:* )
25         cdb? ( || ( >=dev-db/tinycdb-0.76 >=dev-db/cdb-0.75-r4 ) )
26         eai? ( dev-libs/icu:= )
27         ldap? ( net-nds/openldap )
28         ldap-bind? ( net-nds/openldap[sasl] )
29         lmdb? ( >=dev-db/lmdb-0.9.11 )
30         mysql? ( dev-db/mysql-connector-c:0= )
31         nis? ( net-libs/libnsl )
32         pam? ( virtual/pam )
33         postgres? ( dev-db/postgresql:* )
34         sasl? (  >=dev-libs/cyrus-sasl-2 )
35         sqlite? ( dev-db/sqlite:3 )
36         ssl? (
37                 !libressl? ( dev-libs/openssl:0= )
38                 libressl? ( >=dev-libs/libressl-2.9.1:0= )
39         )"
40
41 RDEPEND="${DEPEND}
42         acct-group/postfix
43         acct-group/postdrop
44         acct-user/postfix
45         memcached? ( net-misc/memcached )
46         net-mail/mailbase
47         !mail-mta/courier
48         !mail-mta/esmtp
49         !mail-mta/exim
50         !mail-mta/mini-qmail
51         !mail-mta/msmtp[mta]
52         !mail-mta/netqmail
53         !mail-mta/nullmailer
54         !mail-mta/qmail-ldap
55         !mail-mta/sendmail
56         !mail-mta/opensmtpd
57         !<mail-mta/ssmtp-2.64-r2
58         !>=mail-mta/ssmtp-2.64-r2[mta]
59         !net-mail/fastforward
60         selinux? ( sec-policy/selinux-postfix )"
61
62 REQUIRED_USE="ldap-bind? ( ldap sasl )"
63
64 S="${WORKDIR}/${MY_SRC}"
65
66 PATCHES=(
67         "${FILESDIR}/${PN}-libressl-certkey.patch"
68         "${FILESDIR}/${PN}-libressl-server.patch"
69         "${FILESDIR}/${PN}-glibc230.patch"
70 )
71
72 src_prepare() {
73         default
74         sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
75                 src/util/sys_defs.h || die "sed failed"
76         # change default paths to better comply with portage standard paths
77         sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
78 }
79
80 src_configure() {
81         for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
82         do
83                 local AUXLIBS_${name}=""
84         done
85
86         # Make sure LDFLAGS get passed down to the executables.
87         local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
88         AUXLIBS_PCRE="$(pcre-config --libs)"
89
90         use pam && mylibs="${mylibs} -lpam"
91
92         if use ldap; then
93                 mycc="${mycc} -DHAS_LDAP"
94                 AUXLIBS_LDAP="-lldap -llber"
95         fi
96
97         if use mysql; then
98                 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
99                 AUXLIBS_MYSQL="$(mysql_config --libs)"
100         fi
101
102         if use postgres; then
103                 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
104                 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
105         fi
106
107         if use sqlite; then
108                 mycc="${mycc} -DHAS_SQLITE"
109                 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
110         fi
111
112         if use ssl; then
113                 mycc="${mycc} -DUSE_TLS"
114                 mylibs="${mylibs} -lssl -lcrypto"
115         fi
116
117         if use lmdb; then
118                 mycc="${mycc} -DHAS_LMDB"
119                 AUXLIBS_LMDB="-llmdb -lpthread"
120         fi
121
122         if ! use eai; then
123                 mycc="${mycc} -DNO_EAI"
124         fi
125
126         # broken. and "in other words, not supported" by upstream.
127         # Use inet_protocols setting in main.cf
128         #if ! use ipv6; then
129         #       mycc="${mycc} -DNO_IPV6"
130         #fi
131
132         if use sasl; then
133                 if use dovecot-sasl; then
134                         # Set dovecot as default.
135                         mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
136                 fi
137                 if use ldap-bind; then
138                         mycc="${mycc} -DUSE_LDAP_SASL"
139                 fi
140                 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
141                 mylibs="${mylibs} -lsasl2"
142         elif use dovecot-sasl; then
143                 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
144         fi
145
146         if ! use nis; then
147                 mycc="${mycc} -DNO_NIS"
148         fi
149
150         if ! use berkdb; then
151                 mycc="${mycc} -DNO_DB"
152                 if use cdb; then
153                         # change default hash format from Berkeley DB to cdb
154                         mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
155                 fi
156         fi
157
158         if use cdb; then
159                 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
160                 # Tinycdb is preferred.
161                 if has_version dev-db/tinycdb ; then
162                         einfo "Building with dev-db/tinycdb"
163                         AUXLIBS_CDB="-lcdb"
164                 else
165                         einfo "Building with dev-db/cdb"
166                         CDB_PATH="/usr/$(get_libdir)"
167                         for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
168                                 AUXLIBS_CDB="${AUXLIBS_CDB} ${CDB_PATH}/${i}"
169                         done
170                 fi
171         fi
172
173         # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
174         # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
175         mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
176         filter-lfs-flags
177
178         # Workaround for bug #76512
179         if use hardened; then
180                 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
181         fi
182
183         # Remove annoying C++ comment style warnings - bug #378099
184         append-flags -Wno-comment
185
186         sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
187         sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
188
189         emake makefiles shared=yes dynamicmaps=no pie=yes \
190                 shlib_directory="/usr/$(get_libdir)/postfix/MAIL_VERSION" \
191                 DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" \
192                 AUXLIBS_CDB="${AUXLIBS_CDB}" AUXLIBS_LDAP="${AUXLIBS_LDAP}" \
193                 AUXLIBS_LMDB="${AUXLIBS_LMDB}" AUXLIBS_MYSQL="${AUXLIBS_MYSQL}" \
194                 AUXLIBS_PCRE="${AUXLIBS_PCRE}" AUXLIBS_PGSQL="${AUXLIBS_PGSQL}" \
195                 AUXLIBS_SQLITE="${AUXLIBS_SQLITE}"
196 }
197
198 src_install () {
199         LD_LIBRARY_PATH="${S}/lib" \
200         /bin/sh postfix-install \
201                 -non-interactive \
202                 install_root="${D}" \
203                 config_directory="/etc/postfix" \
204                 manpage_directory="/usr/share/man" \
205                 command_directory="/usr/sbin" \
206                 mailq_path="/usr/bin/mailq" \
207                 newaliases_path="/usr/bin/newaliases" \
208                 sendmail_path="/usr/sbin/sendmail" \
209                 || die "postfix-install failed"
210
211         # Fix spool removal on upgrade
212         rm -Rf "${D}"/var
213         keepdir /var/spool/postfix
214
215         # Install rmail for UUCP, closes bug #19127
216         dobin auxiliary/rmail/rmail
217
218         # Provide another link for legacy FSH
219         dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
220
221         # Install qshape, posttls-finger and collate
222         dobin auxiliary/qshape/qshape.pl
223         doman man/man1/qshape.1
224         dobin bin/posttls-finger
225         doman man/man1/posttls-finger.1
226         dobin auxiliary/collate/collate.pl
227         newdoc auxiliary/collate/README README.collate
228
229         # Performance tuning tools and their manuals
230         dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
231         doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
232
233         # Set proper permissions on required files/directories
234         keepdir /var/lib/postfix
235         fowners -R postfix:postfix /var/lib/postfix
236         fperms 0750 /var/lib/postfix
237         fowners root:postdrop /usr/sbin/post{drop,queue}
238         fperms 02755 /usr/sbin/post{drop,queue}
239
240         keepdir /etc/postfix
241         keepdir /etc/postfix/postfix-files.d
242         if use mbox; then
243                 mypostconf="mail_spool_directory=/var/spool/mail"
244         else
245                 mypostconf="home_mailbox=.maildir/"
246         fi
247         LD_LIBRARY_PATH="${S}/lib" \
248         "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
249                 -e ${mypostconf} || die "postconf failed"
250
251         insinto /etc/postfix
252         newins "${FILESDIR}"/smtp.pass saslpass
253         fperms 600 /etc/postfix/saslpass
254
255         newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
256         # do not start mysql/postgres unnecessarily - bug #359913
257         use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
258         use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
259
260         dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
261         mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
262         # postfix set-permissions expects uncompressed man files
263         docompress -x /usr/share/man
264
265         pamd_mimic_system smtp auth account
266
267         if use sasl; then
268                 insinto /etc/sasl2
269                 newins "${FILESDIR}"/smtp.sasl smtpd.conf
270         fi
271
272         # header files
273         insinto /usr/include/postfix
274         doins include/*.h
275
276         if has_version mail-mta/postfix; then
277                 # let the sysadmin decide when to change the compatibility_level
278                 sed -i -e /^compatibility_level/"s/^/#/" "${D}"/etc/postfix/main.cf || die
279         fi
280
281         systemd_dounit "${FILESDIR}/${PN}.service"
282 }
283
284 pkg_preinst() {
285         if has_version '<mail-mta/postfix-3.4'; then
286                 elog
287                 elog "Postfix-3.4 introduces a new master.cf service 'postlog'"
288                 elog "with type 'unix-dgram' that is used by the new postlogd(8) daemon."
289                 elog "Before backing out to an older Postfix version, edit the master.cf"
290                 elog "file and remove the postlog entry."
291                 elog
292         fi
293 }
294
295 pkg_postinst() {
296         if [[ ! -e /etc/mail/aliases.db ]] ; then
297                 ewarn
298                 ewarn "You must edit /etc/mail/aliases to suit your needs"
299                 ewarn "and then run /usr/bin/newaliases. Postfix will not"
300                 ewarn "work correctly without it."
301                 ewarn
302         fi
303
304         # check and fix file permissions
305         "${EROOT}"/usr/sbin/postfix set-permissions
306
307         # configure tls
308         if use ssl ; then
309                 if "${EROOT}"/usr/sbin/postfix tls all-default-client; then
310                         elog "To configure client side TLS settings:"
311                         elog "${EROOT}"/usr/sbin/postfix tls enable-client
312                 fi
313                 if "${EROOT}"/usr/sbin/postfix tls all-default-server; then
314                         elog "To configure server side TLS settings:"
315                         elog "${EROOT}"/usr/sbin/postfix tls enable-server
316                 fi
317         fi
318 }