mail-mta/protonmail-bridge-bin-1.2.7: version bump
[gentoo.git] / mail-mta / postfix / postfix-3.4.9.ebuild
1 # Copyright 1999-2020 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 ~s390 ~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? ( sys-libs/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         "${FILESDIR}/${PN}-gcc10.patch"
71 )
72
73 src_prepare() {
74         default
75         sed -i -e "/^#define ALIAS_DB_MAP/s|:/etc/aliases|:/etc/mail/aliases|" \
76                 src/util/sys_defs.h || die "sed failed"
77         # change default paths to better comply with portage standard paths
78         sed -i -e "s:/usr/local/:/usr/:g" conf/master.cf || die "sed failed"
79 }
80
81 src_configure() {
82         for name in CDB LDAP LMDB MYSQL PCRE PGSQL SDBM SQLITE
83         do
84                 local AUXLIBS_${name}=""
85         done
86
87         # Make sure LDFLAGS get passed down to the executables.
88         local mycc="-DHAS_PCRE" mylibs="${LDFLAGS} -ldl"
89         AUXLIBS_PCRE="$(pcre-config --libs)"
90
91         use pam && mylibs="${mylibs} -lpam"
92
93         if use ldap; then
94                 mycc="${mycc} -DHAS_LDAP"
95                 AUXLIBS_LDAP="-lldap -llber"
96         fi
97
98         if use mysql; then
99                 mycc="${mycc} -DHAS_MYSQL $(mysql_config --include)"
100                 AUXLIBS_MYSQL="$(mysql_config --libs)"
101         fi
102
103         if use postgres; then
104                 mycc="${mycc} -DHAS_PGSQL -I$(pg_config --includedir)"
105                 AUXLIBS_PGSQL="-L$(pg_config --libdir) -lpq"
106         fi
107
108         if use sqlite; then
109                 mycc="${mycc} -DHAS_SQLITE"
110                 AUXLIBS_SQLITE="-lsqlite3 -lpthread"
111         fi
112
113         if use ssl; then
114                 mycc="${mycc} -DUSE_TLS"
115                 mylibs="${mylibs} -lssl -lcrypto"
116         fi
117
118         if use lmdb; then
119                 mycc="${mycc} -DHAS_LMDB"
120                 AUXLIBS_LMDB="-llmdb -lpthread"
121         fi
122
123         if ! use eai; then
124                 mycc="${mycc} -DNO_EAI"
125         fi
126
127         # broken. and "in other words, not supported" by upstream.
128         # Use inet_protocols setting in main.cf
129         #if ! use ipv6; then
130         #       mycc="${mycc} -DNO_IPV6"
131         #fi
132
133         if use sasl; then
134                 if use dovecot-sasl; then
135                         # Set dovecot as default.
136                         mycc="${mycc} -DDEF_SASL_SERVER=\\\"dovecot\\\""
137                 fi
138                 if use ldap-bind; then
139                         mycc="${mycc} -DUSE_LDAP_SASL"
140                 fi
141                 mycc="${mycc} -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl"
142                 mylibs="${mylibs} -lsasl2"
143         elif use dovecot-sasl; then
144                 mycc="${mycc} -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\\\"dovecot\\\""
145         fi
146
147         if ! use nis; then
148                 mycc="${mycc} -DNO_NIS"
149         fi
150
151         if ! use berkdb; then
152                 mycc="${mycc} -DNO_DB"
153                 if use cdb; then
154                         # change default hash format from Berkeley DB to cdb
155                         mycc="${mycc} -DDEF_DB_TYPE=\\\"cdb\\\""
156                 fi
157         fi
158
159         if use cdb; then
160                 mycc="${mycc} -DHAS_CDB -I/usr/include/cdb"
161                 # Tinycdb is preferred.
162                 if has_version dev-db/tinycdb ; then
163                         einfo "Building with dev-db/tinycdb"
164                         AUXLIBS_CDB="-lcdb"
165                 else
166                         einfo "Building with dev-db/cdb"
167                         CDB_PATH="/usr/$(get_libdir)"
168                         for i in cdb.a alloc.a buffer.a unix.a byte.a ; do
169                                 AUXLIBS_CDB="${AUXLIBS_CDB} ${CDB_PATH}/${i}"
170                         done
171                 fi
172         fi
173
174         # Robin H. Johnson <robbat2@gentoo.org> 17/Nov/2006
175         # Fix because infra boxes hit 2Gb .db files that fail a 32-bit fstat signed check.
176         mycc="${mycc} -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
177         filter-lfs-flags
178
179         # Workaround for bug #76512
180         if use hardened; then
181                 [[ "$(gcc-version)" == "3.4" ]] && replace-flags -O? -Os
182         fi
183
184         # Remove annoying C++ comment style warnings - bug #378099
185         append-flags -Wno-comment
186
187         sed -i -e "/^RANLIB/s/ranlib/$(tc-getRANLIB)/g" "${S}"/makedefs
188         sed -i -e "/^AR/s/ar/$(tc-getAR)/g" "${S}"/makedefs
189
190         emake makefiles shared=yes dynamicmaps=no pie=yes \
191                 shlib_directory="/usr/$(get_libdir)/postfix/MAIL_VERSION" \
192                 DEBUG="" CC="$(tc-getCC)" OPT="${CFLAGS}" CCARGS="${mycc}" AUXLIBS="${mylibs}" \
193                 AUXLIBS_CDB="${AUXLIBS_CDB}" AUXLIBS_LDAP="${AUXLIBS_LDAP}" \
194                 AUXLIBS_LMDB="${AUXLIBS_LMDB}" AUXLIBS_MYSQL="${AUXLIBS_MYSQL}" \
195                 AUXLIBS_PCRE="${AUXLIBS_PCRE}" AUXLIBS_PGSQL="${AUXLIBS_PGSQL}" \
196                 AUXLIBS_SQLITE="${AUXLIBS_SQLITE}"
197 }
198
199 src_install() {
200         LD_LIBRARY_PATH="${S}/lib" \
201         /bin/sh postfix-install \
202                 -non-interactive \
203                 install_root="${D}" \
204                 config_directory="/etc/postfix" \
205                 manpage_directory="/usr/share/man" \
206                 command_directory="/usr/sbin" \
207                 mailq_path="/usr/bin/mailq" \
208                 newaliases_path="/usr/bin/newaliases" \
209                 sendmail_path="/usr/sbin/sendmail" \
210                 || die "postfix-install failed"
211
212         # Fix spool removal on upgrade
213         rm -Rf "${D}"/var
214         keepdir /var/spool/postfix
215
216         # Install rmail for UUCP, closes bug #19127
217         dobin auxiliary/rmail/rmail
218
219         # Provide another link for legacy FSH
220         dosym ../sbin/sendmail /usr/$(get_libdir)/sendmail
221
222         # Install qshape, posttls-finger and collate
223         dobin auxiliary/qshape/qshape.pl
224         doman man/man1/qshape.1
225         dobin bin/posttls-finger
226         doman man/man1/posttls-finger.1
227         dobin auxiliary/collate/collate.pl
228         newdoc auxiliary/collate/README README.collate
229
230         # Performance tuning tools and their manuals
231         dosbin bin/smtp-{source,sink} bin/qmqp-{source,sink}
232         doman man/man1/smtp-{source,sink}.1 man/man1/qmqp-{source,sink}.1
233
234         # Set proper permissions on required files/directories
235         keepdir /var/lib/postfix
236         fowners -R postfix:postfix /var/lib/postfix
237         fperms 0750 /var/lib/postfix
238         fowners root:postdrop /usr/sbin/post{drop,queue}
239         fperms 02755 /usr/sbin/post{drop,queue}
240
241         keepdir /etc/postfix
242         keepdir /etc/postfix/postfix-files.d
243         if use mbox; then
244                 mypostconf="mail_spool_directory=/var/spool/mail"
245         else
246                 mypostconf="home_mailbox=.maildir/"
247         fi
248         LD_LIBRARY_PATH="${S}/lib" \
249         "${D}"/usr/sbin/postconf -c "${D}"/etc/postfix \
250                 -e ${mypostconf} || die "postconf failed"
251
252         insinto /etc/postfix
253         newins "${FILESDIR}"/smtp.pass saslpass
254         fperms 600 /etc/postfix/saslpass
255
256         newinitd "${FILESDIR}"/postfix.rc6.${RC_VER} postfix
257         # do not start mysql/postgres unnecessarily - bug #359913
258         use mysql || sed -i -e "s/mysql //" "${D}/etc/init.d/postfix"
259         use postgres || sed -i -e "s/postgresql //" "${D}/etc/init.d/postfix"
260
261         dodoc *README COMPATIBILITY HISTORY PORTING RELEASE_NOTES*
262         mv "${S}"/examples "${D}"/usr/share/doc/${PF}/
263         # postfix set-permissions expects uncompressed man files
264         docompress -x /usr/share/man
265
266         pamd_mimic_system smtp auth account
267
268         if use sasl; then
269                 insinto /etc/sasl2
270                 newins "${FILESDIR}"/smtp.sasl smtpd.conf
271         fi
272
273         # header files
274         insinto /usr/include/postfix
275         doins include/*.h
276
277         if has_version mail-mta/postfix; then
278                 # let the sysadmin decide when to change the compatibility_level
279                 sed -i -e /^compatibility_level/"s/^/#/" "${D}"/etc/postfix/main.cf || die
280         fi
281
282         systemd_dounit "${FILESDIR}/${PN}.service"
283 }
284
285 pkg_preinst() {
286         if has_version '<mail-mta/postfix-3.4'; then
287                 elog
288                 elog "Postfix-3.4 introduces a new master.cf service 'postlog'"
289                 elog "with type 'unix-dgram' that is used by the new postlogd(8) daemon."
290                 elog "Before backing out to an older Postfix version, edit the master.cf"
291                 elog "file and remove the postlog entry."
292                 elog
293         fi
294 }
295
296 pkg_postinst() {
297         if [[ ! -e /etc/mail/aliases.db ]] ; then
298                 ewarn
299                 ewarn "You must edit /etc/mail/aliases to suit your needs"
300                 ewarn "and then run /usr/bin/newaliases. Postfix will not"
301                 ewarn "work correctly without it."
302                 ewarn
303         fi
304
305         # check and fix file permissions
306         "${EROOT}"/usr/sbin/postfix set-permissions
307
308         # configure tls
309         if use ssl ; then
310                 if "${EROOT}"/usr/sbin/postfix tls all-default-client; then
311                         elog "To configure client side TLS settings:"
312                         elog "${EROOT}"/usr/sbin/postfix tls enable-client
313                 fi
314                 if "${EROOT}"/usr/sbin/postfix tls all-default-server; then
315                         elog "To configure server side TLS settings:"
316                         elog "${EROOT}"/usr/sbin/postfix tls enable-server
317                 fi
318         fi
319 }