1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 PYTHON_COMPAT=( python3_{6,7} )
7 inherit autotools flag-o-matic multilib-minimal python-single-r1 systemd user
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"
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 )"
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
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}] )
32 dev-libs/fstrm[${MULTILIB_USEDEP}]
33 >=dev-libs/protobuf-c-1.0.2-r1[${MULTILIB_USEDEP}]
36 !libressl? ( dev-libs/openssl:0[-bindist] )
38 python? ( ${PYTHON_DEPS} )
39 redis? ( dev-libs/hiredis:= )"
41 BDEPEND="virtual/pkgconfig"
44 python? ( dev-lang/swig )
46 net-dns/ldns-utils[examples]
50 systemd? ( sys-apps/systemd )"
54 selinux? ( sec-policy/selinux-bind )"
61 "${FILESDIR}"/${PN}-1.5.7-trust-anchor-file.patch
62 "${FILESDIR}"/${PN}-1.6.3-pkg-config.patch
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"
76 use python && python-single-r1_pkg_setup
84 # required for the python part
89 [[ ${CHOST} == *-darwin* ]] || append-ldflags -Wl,-z,noexecstack
90 multilib-minimal_src_configure
93 multilib_src_configure() {
97 $(use_enable dnscrypt) \
98 $(use_enable dnstap) \
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) \
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
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) \
127 multilib_src_install_all() {
128 use python && python_optimize
130 newinitd "${FILESDIR}"/unbound-r1.initd unbound
131 newconfd "${FILESDIR}"/unbound-r1.confd unbound
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
138 dodoc doc/{README,CREDITS,TODO,Changelog,FEATURES}
141 dodoc contrib/unbound_munin_
144 dodoc contrib/selinux/*
146 exeinto /usr/share/${PN}
147 doexe contrib/update-anchor.sh
149 # create space for auto-trust-anchor-file...
150 keepdir /etc/unbound/var
151 # ... and point example config to it
153 -e '/# auto-trust-anchor-file:/s,/etc/dnssec/root-anchors.txt,/etc/unbound/var/root-anchors.txt,' \
154 "${ED}/etc/unbound/unbound.conf" || \
157 # Used to store cache data
158 keepdir /var/lib/${PN}
159 fowners root:unbound /var/lib/${PN}
160 fperms 0750 /var/lib/${PN}
162 find "${ED}" -name '*.la' -delete || die
163 if ! use static-libs ; then
164 find "${ED}" -name "*.a" -delete || die
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"
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"
179 einfo " su -s /bin/sh -c '${EROOT}/usr/sbin/unbound-anchor -a ${EROOT}/etc/unbound/var/root-anchors.txt' unbound"
181 einfo "as root to create it initially before starting unbound for the first time after enabling this."