net-dns/dnsmasq: amd64 stable wrt bug #632692
[gentoo.git] / net-dns / dnsmasq / dnsmasq-2.76-r1.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit eutils toolchain-funcs flag-o-matic user systemd
7
8 DESCRIPTION="Small forwarding DNS server"
9 HOMEPAGE="http://www.thekelleys.org.uk/dnsmasq/doc.html"
10 SRC_URI="http://www.thekelleys.org.uk/dnsmasq/${P}.tar.xz"
11
12 LICENSE="|| ( GPL-2 GPL-3 )"
13 SLOT="0"
14 KEYWORDS="~alpha amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc x86 ~sparc-fbsd ~x86-fbsd"
15 IUSE="auth-dns conntrack dbus +dhcp dhcp-tools dnssec idn +inotify ipv6 lua nls script selinux static tftp"
16 DM_LINGUAS="de es fi fr id it no pl pt_BR ro"
17 for dm_lingua in ${DM_LINGUAS}; do
18         IUSE+=" linguas_${dm_lingua}"
19 done
20
21 CDEPEND="dbus? ( sys-apps/dbus )
22         idn? ( net-dns/libidn )
23         lua? ( dev-lang/lua:* )
24         conntrack? ( net-libs/libnetfilter_conntrack )
25         nls? (
26                 sys-devel/gettext
27                 net-dns/libidn
28         )
29 "
30
31 DEPEND="${CDEPEND}
32         app-arch/xz-utils
33         dnssec? (
34                 dev-libs/nettle[gmp]
35                 static? (
36                         dev-libs/nettle[static-libs(+)]
37                 )
38         )
39         virtual/pkgconfig"
40
41 RDEPEND="${CDEPEND}
42         dnssec? (
43                 !static? (
44                         dev-libs/nettle[gmp]
45                 )
46         )
47         selinux? ( sec-policy/selinux-dnsmasq )
48 "
49
50 REQUIRED_USE="dhcp-tools? ( dhcp )
51         lua? ( script )"
52
53 use_have() {
54         local useflag no_only uword
55         if [[ $1 == '-n' ]]; then
56                 no_only=1
57                 shift
58         fi
59         useflag="${1}"
60         shift
61
62         uword="${1:-${useflag}}"
63         shift
64
65         while [[ ${uword} ]]; do
66                 uword="${uword^^}"
67
68                 if ! use "${useflag}"; then
69                         echo -n " -DNO_${uword}"
70                 elif [[ -z "${no_only}" ]]; then
71                         echo -n " -DHAVE_${uword}"
72                 fi
73                 uword="${1}"
74                 shift
75         done
76 }
77
78 pkg_pretend() {
79         if use static; then
80                 einfo "Only sys-libs/gmp and dev-libs/nettle are statically linked."
81                 use dnssec || einfo "Thus, ${P}[!dnssec,static] makes no sense; the static USE flag is ignored."
82         fi
83 }
84
85 pkg_setup() {
86         enewgroup dnsmasq
87         enewuser dnsmasq -1 -1 /dev/null dnsmasq
88 }
89
90 src_prepare() {
91         default
92
93         sed -i -r 's:lua5.[0-9]+:lua:' Makefile
94         sed -i "s:%%PREFIX%%:${EPREFIX}/usr:" dnsmasq.conf.example
95 }
96
97 src_configure() {
98         COPTS="$(use_have -n auth-dns auth)"
99         COPTS+="$(use_have conntrack)"
100         COPTS+="$(use_have dbus)"
101         COPTS+="$(use_have idn)"
102         COPTS+="$(use_have -n inotify)"
103         COPTS+="$(use_have -n dhcp dhcp dhcp6)"
104         COPTS+="$(use_have -n ipv6 ipv6 dhcp6)"
105         COPTS+="$(use_have lua luascript)"
106         COPTS+="$(use_have -n script)"
107         COPTS+="$(use_have -n tftp)"
108         COPTS+="$(use_have dnssec)"
109         COPTS+="$(use_have static dnssec_static)"
110 }
111
112 src_compile() {
113         emake \
114                 PREFIX=/usr \
115                 MANDIR=/usr/share/man \
116                 CC="$(tc-getCC)" \
117                 PKG_CONFIG="$(tc-getPKG_CONFIG)" \
118                 CFLAGS="${CFLAGS}" \
119                 LDFLAGS="${LDFLAGS}" \
120                 COPTS="${COPTS}" \
121                 CONFFILE="/etc/${PN}.conf" \
122                 all$(use nls && echo "-i18n")
123
124         use dhcp-tools && emake -C contrib/lease-tools \
125                 PREFIX=/usr \
126                 MANDIR=/usr/share/man \
127                 CC="$(tc-getCC)" \
128                 PKG_CONFIG="$(tc-getPKG_CONFIG)" \
129                 CFLAGS="${CFLAGS}" \
130                 LDFLAGS="${LDFLAGS}" \
131                 all
132 }
133
134 src_install() {
135         local lingua puid
136         emake \
137                 PREFIX=/usr \
138                 MANDIR=/usr/share/man \
139                 COPTS="${COPTS}" \
140                 DESTDIR="${D}" \
141                 install$(use nls && echo "-i18n")
142
143         for lingua in ${DM_LINGUAS}; do
144                 use linguas_${lingua} || rm -rf "${D}"/usr/share/locale/${lingua}
145         done
146         [[ -d "${D}"/usr/share/locale/ ]] && rmdir --ignore-fail-on-non-empty "${D}"/usr/share/locale/
147
148         dodoc CHANGELOG CHANGELOG.archive FAQ dnsmasq.conf.example
149         dodoc -r logo
150
151         docinto html/
152         dodoc *.html
153
154         newinitd "${FILESDIR}"/dnsmasq-init-r2 ${PN}
155         newconfd "${FILESDIR}"/dnsmasq.confd-r1 ${PN}
156
157         insinto /etc
158         newins dnsmasq.conf.example dnsmasq.conf
159
160         insinto /usr/share/dnsmasq
161         doins trust-anchors.conf
162
163         if use dhcp; then
164                 dodir /var/lib/misc
165                 newinitd "${FILESDIR}"/dnsmasq-init-dhcp-r1 ${PN}
166         fi
167         if use dbus; then
168                 insinto /etc/dbus-1/system.d
169                 doins dbus/dnsmasq.conf
170         fi
171
172         if use dhcp-tools; then
173                 dosbin contrib/lease-tools/{dhcp_release,dhcp_lease_time}
174                 doman contrib/lease-tools/{dhcp_release,dhcp_lease_time}.1
175                 if use ipv6; then
176                         dosbin contrib/lease-tools/dhcp_release6
177                         doman contrib/lease-tools/dhcp_release6.1
178                 fi
179         fi
180
181         systemd_newunit "${FILESDIR}"/${PN}.service-r1 ${PN}.service
182 }
183
184 pkg_preinst() {
185         # temporary workaround to (hopefully) prevent leases file from being removed
186         [[ -f /var/lib/misc/dnsmasq.leases ]] && cp /var/lib/misc/dnsmasq.leases "${T}"
187 }
188
189 pkg_postinst() {
190         # temporary workaround to (hopefully) prevent leases file from being removed
191         [[ -f "${T}"/dnsmasq.leases ]] && cp "${T}"/dnsmasq.leases /var/lib/misc/dnsmasq.leases
192 }