*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / net-dns / unbound / unbound-1.9.6.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5 PYTHON_COMPAT=( python2_7 python3_{6,7} )
6
7 inherit autotools flag-o-matic multilib-minimal python-single-r1 systemd user
8
9 MY_P=${PN}-${PV/_/}
10 DESCRIPTION="A validating, recursive and caching DNS resolver"
11 HOMEPAGE="https://unbound.net/ https://nlnetlabs.nl/projects/unbound/about/"
12 SRC_URI="https://nlnetlabs.nl/downloads/unbound/${MY_P}.tar.gz"
13
14 LICENSE="BSD GPL-2"
15 SLOT="0/8" # ABI version of libunbound.so
16 KEYWORDS="~alpha amd64 arm ~arm64 ~hppa ~mips ppc ppc64 x86"
17 IUSE="debug dnscrypt dnstap +ecdsa ecs gost libressl python redis selinux static-libs systemd test threads"
18 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
19 RESTRICT="!test? ( test )"
20
21 # Note: expat is needed by executable only but the Makefile is custom
22 # and doesn't make it possible to easily install the library without
23 # the executables. MULTILIB_USEDEP may be dropped once build system
24 # is fixed.
25
26 CDEPEND=">=dev-libs/expat-2.1.0-r3[${MULTILIB_USEDEP}]
27         >=dev-libs/libevent-2.0.21:0=[${MULTILIB_USEDEP}]
28         libressl? ( >=dev-libs/libressl-2.2.4:0[${MULTILIB_USEDEP}] )
29         !libressl? ( >=dev-libs/openssl-1.0.1h-r2:0=[${MULTILIB_USEDEP}] )
30         dnscrypt? ( dev-libs/libsodium[${MULTILIB_USEDEP}] )
31         dnstap? (
32                 dev-libs/fstrm[${MULTILIB_USEDEP}]
33                 >=dev-libs/protobuf-c-1.0.2-r1[${MULTILIB_USEDEP}]
34         )
35         ecdsa? (
36                 !libressl? ( dev-libs/openssl:0[-bindist] )
37         )
38         python? ( ${PYTHON_DEPS} )
39         redis? ( dev-libs/hiredis:= )"
40
41 BDEPEND="virtual/pkgconfig"
42
43 DEPEND="${CDEPEND}
44         python? ( dev-lang/swig )
45         test? (
46                 net-dns/ldns-utils[examples]
47                 dev-util/splint
48                 app-text/wdiff
49         )
50         systemd? ( sys-apps/systemd )"
51
52 RDEPEND="${CDEPEND}
53         net-dns/dnssec-root
54         selinux? ( sec-policy/selinux-bind )"
55
56 # bug #347415
57 RDEPEND="${RDEPEND}
58         net-dns/dnssec-root"
59
60 PATCHES=(
61         "${FILESDIR}"/${PN}-1.5.7-trust-anchor-file.patch
62         "${FILESDIR}"/${PN}-1.6.3-pkg-config.patch
63 )
64
65 S=${WORKDIR}/${MY_P}
66
67 pkg_setup() {
68         enewgroup unbound
69         enewuser unbound -1 -1 /etc/unbound unbound
70         # improve security on existing installs (bug #641042)
71         # as well as new installs where unbound homedir has just been created
72         if [[ -d "${ROOT}/etc/unbound" ]]; then
73                 chown --no-dereference --from=unbound root "${ROOT}/etc/unbound"
74         fi
75
76         use python && python-single-r1_pkg_setup
77 }
78
79 src_prepare() {
80         default
81
82         eautoreconf
83
84         # required for the python part
85         multilib_copy_sources
86 }
87
88 src_configure() {
89         [[ ${CHOST} == *-darwin* ]] || append-ldflags -Wl,-z,noexecstack
90         multilib-minimal_src_configure
91 }
92
93 multilib_src_configure() {
94         econf \
95                 $(use_enable debug) \
96                 $(use_enable gost) \
97                 $(use_enable dnscrypt) \
98                 $(use_enable dnstap) \
99                 $(use_enable ecdsa) \
100                 $(use_enable ecs subnet) \
101                 $(multilib_native_use_enable redis cachedb) \
102                 $(use_enable static-libs static) \
103                 $(use_enable systemd) \
104                 $(multilib_native_use_with python pythonmodule) \
105                 $(multilib_native_use_with python pyunbound) \
106                 $(use_with threads pthreads) \
107                 --disable-flto \
108                 --disable-rpath \
109                 --enable-event-api \
110                 --enable-ipsecmod \
111                 --enable-tfo-client \
112                 --enable-tfo-server \
113                 --with-libevent="${EPREFIX}"/usr \
114                 $(multilib_native_usex redis --with-libhiredis="${EPREFIX}/usr" --without-libhiredis) \
115                 --with-pidfile="${EPREFIX}"/run/unbound.pid \
116                 --with-rootkey-file="${EPREFIX}"/etc/dnssec/root-anchors.txt \
117                 --with-ssl="${EPREFIX}"/usr \
118                 --with-libexpat="${EPREFIX}"/usr
119
120                 # http://unbound.nlnetlabs.nl/pipermail/unbound-users/2011-April/001801.html
121                 # $(use_enable debug lock-checks) \
122                 # $(use_enable debug alloc-checks) \
123                 # $(use_enable debug alloc-lite) \
124                 # $(use_enable debug alloc-nonregional) \
125 }
126
127 multilib_src_install_all() {
128         use python && python_optimize
129
130         newinitd "${FILESDIR}"/unbound-r1.initd unbound
131         newconfd "${FILESDIR}"/unbound-r1.confd unbound
132
133         systemd_dounit "${FILESDIR}"/unbound.service
134         systemd_dounit "${FILESDIR}"/unbound.socket
135         systemd_newunit "${FILESDIR}"/unbound_at.service "unbound@.service"
136         systemd_dounit "${FILESDIR}"/unbound-anchor.service
137
138         dodoc doc/{README,CREDITS,TODO,Changelog,FEATURES}
139
140         # bug #315519
141         dodoc contrib/unbound_munin_
142
143         docinto selinux
144         dodoc contrib/selinux/*
145
146         exeinto /usr/share/${PN}
147         doexe contrib/update-anchor.sh
148
149         # create space for auto-trust-anchor-file...
150         keepdir /etc/unbound/var
151         # ... and point example config to it
152         sed -i \
153                 -e '/# auto-trust-anchor-file:/s,/etc/dnssec/root-anchors.txt,/etc/unbound/var/root-anchors.txt,' \
154                 "${ED}/etc/unbound/unbound.conf" || \
155                 die
156
157         # Used to store cache data
158         keepdir /var/lib/${PN}
159         fowners root:unbound /var/lib/${PN}
160         fperms 0750 /var/lib/${PN}
161
162         find "${ED}" -name '*.la' -delete || die
163         if ! use static-libs ; then
164                 find "${ED}" -name "*.a" -delete || die
165         fi
166 }
167
168 pkg_postinst() {
169         # make var/ writable by unbound
170         if [[ -d "${EROOT}/etc/unbound/var" ]]; then
171                 chown --no-dereference --from=root unbound: "${EROOT}/etc/unbound/var"
172         fi
173
174         einfo ""
175         einfo "If you want unbound to automatically update the root-anchor file for DNSSEC validation"
176         einfo "set 'auto-trust-anchor-file: ${EROOT}/etc/unbound/var/root-anchors.txt' in ${EROOT}/etc/unbound/unbound.conf"
177         einfo "and run"
178         einfo ""
179         einfo "  su -s /bin/sh -c '${EROOT}/usr/sbin/unbound-anchor -a ${EROOT}/etc/unbound/var/root-anchors.txt' unbound"
180         einfo ""
181         einfo "as root to create it initially before starting unbound for the first time after enabling this."
182         einfo ""
183 }