581677ab6175d59275584adc5a754d84420c7433
[gentoo.git] / app-emulation / libvirt / libvirt-5.5.0-r1.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 PYTHON_COMPAT=( python3_{5,6,7} )
7
8 inherit autotools bash-completion-r1 eutils linux-info python-any-r1 readme.gentoo-r1 systemd
9
10 if [[ ${PV} = *9999* ]]; then
11         inherit git-r3
12         EGIT_REPO_URI="https://libvirt.org/git/libvirt.git"
13         SRC_URI=""
14         KEYWORDS="amd64 x86"
15         SLOT="0"
16 else
17         SRC_URI="https://libvirt.org/sources/${P}.tar.xz"
18         KEYWORDS="amd64 ~arm64 x86"
19         SLOT="0/${PV}"
20 fi
21
22 DESCRIPTION="C toolkit to manipulate virtual machines"
23 HOMEPAGE="http://www.libvirt.org/"
24 LICENSE="LGPL-2.1"
25 IUSE="
26         apparmor audit +caps +dbus dtrace firewalld fuse glusterfs iscsi
27         iscsi-direct +libvirtd lvm libssh lxc +macvtap nfs nls numa openvz
28         parted pcap phyp policykit +qemu rbd sasl selinux +udev +vepa
29         virtualbox virt-network wireshark-plugins xen zfs
30 "
31
32 REQUIRED_USE="
33         firewalld? ( virt-network )
34         libvirtd? ( || ( lxc openvz qemu virtualbox xen ) )
35         lxc? ( caps libvirtd )
36         openvz? ( libvirtd )
37         policykit? ( dbus )
38         qemu? ( libvirtd )
39         vepa? ( macvtap )
40         virt-network? ( libvirtd )
41         virtualbox? ( libvirtd )
42         xen? ( libvirtd )"
43
44 # gettext.sh command is used by the libvirt command wrappers, and it's
45 # non-optional, so put it into RDEPEND.
46 # We can use both libnl:1.1 and libnl:3, but if you have both installed, the
47 # package will use 3 by default. Since we don't have slot pinning in an API,
48 # we must go with the most recent
49 RDEPEND="
50         acct-user/qemu
51         policykit? ( acct-group/libvirt )
52         app-misc/scrub
53         dev-libs/libgcrypt:0
54         dev-libs/libnl:3
55         >=dev-libs/libxml2-2.7.6
56         >=net-analyzer/openbsd-netcat-1.105-r1
57         >=net-libs/gnutls-1.0.25:0=
58         net-libs/libssh2
59         net-libs/libtirpc
60         net-libs/rpcsvc-proto
61         >=net-misc/curl-7.18.0
62         sys-apps/dmidecode
63         !sys-apps/systemd[-cgroup-hybrid(+)]
64         >=sys-apps/util-linux-2.17
65         sys-devel/gettext
66         sys-libs/ncurses:0=
67         sys-libs/readline:=
68         apparmor? ( sys-libs/libapparmor )
69         audit? ( sys-process/audit )
70         caps? ( sys-libs/libcap-ng )
71         dbus? ( sys-apps/dbus )
72         dtrace? ( dev-util/systemtap )
73         firewalld? ( >=net-firewall/firewalld-0.6.3 )
74         fuse? ( >=sys-fs/fuse-2.8.6:= )
75         glusterfs? ( >=sys-cluster/glusterfs-3.4.1 )
76         iscsi? ( sys-block/open-iscsi )
77         iscsi-direct? ( >=net-libs/libiscsi-1.18.0 )
78         libssh? ( net-libs/libssh )
79         lvm? ( >=sys-fs/lvm2-2.02.48-r2[-device-mapper-only(-)] )
80         nfs? ( net-fs/nfs-utils )
81         numa? (
82                 >sys-process/numactl-2.0.2
83                 sys-process/numad
84         )
85         parted? (
86                 >=sys-block/parted-1.8[device-mapper]
87                 sys-fs/lvm2[-device-mapper-only(-)]
88         )
89         pcap? ( >=net-libs/libpcap-1.0.0 )
90         policykit? ( >=sys-auth/polkit-0.9 )
91         qemu? (
92                 >=app-emulation/qemu-1.5.0
93                 dev-libs/yajl
94         )
95         rbd? ( sys-cluster/ceph )
96         sasl? ( dev-libs/cyrus-sasl )
97         selinux? ( >=sys-libs/libselinux-2.0.85 )
98         virt-network? (
99                 net-dns/dnsmasq[script]
100                 net-firewall/ebtables
101                 >=net-firewall/iptables-1.4.10[ipv6]
102                 net-misc/radvd
103                 sys-apps/iproute2[-minimal]
104         )
105         virtualbox? ( || ( app-emulation/virtualbox >=app-emulation/virtualbox-bin-2.2.0 ) )
106         wireshark-plugins? ( net-analyzer/wireshark:= )
107         xen? (
108                 >=app-emulation/xen-4.6.0
109                 app-emulation/xen-tools:=
110         )
111         udev? (
112                 virtual/udev
113                 >=x11-libs/libpciaccess-0.10.9
114         )
115         zfs? ( sys-fs/zfs )"
116
117 DEPEND="${RDEPEND}
118         ${PYTHON_DEPS}
119         app-text/xhtml1
120         dev-lang/perl
121         dev-libs/libxslt
122         dev-perl/XML-XPath
123         virtual/pkgconfig"
124
125 PATCHES=(
126         "${FILESDIR}"/${PN}-5.2.0-do-not-use-sysconf.patch
127         "${FILESDIR}"/${PN}-1.2.16-fix_paths_in_libvirt-guests_sh.patch
128         "${FILESDIR}"/${PN}-5.2.0-fix-paths-for-apparmor.patch
129 )
130
131 pkg_setup() {
132         # Check kernel configuration:
133         CONFIG_CHECK=""
134         use fuse && CONFIG_CHECK+="
135                 ~FUSE_FS"
136
137         use lvm && CONFIG_CHECK+="
138                 ~BLK_DEV_DM
139                 ~DM_MULTIPATH
140                 ~DM_SNAPSHOT"
141
142         use lxc && CONFIG_CHECK+="
143                 ~BLK_CGROUP
144                 ~CGROUP_CPUACCT
145                 ~CGROUP_DEVICE
146                 ~CGROUP_FREEZER
147                 ~CGROUP_NET_PRIO
148                 ~CGROUP_PERF
149                 ~CGROUPS
150                 ~CGROUP_SCHED
151                 ~CPUSETS
152                 ~IPC_NS
153                 ~MACVLAN
154                 ~NAMESPACES
155                 ~NET_CLS_CGROUP
156                 ~NET_NS
157                 ~PID_NS
158                 ~POSIX_MQUEUE
159                 ~SECURITYFS
160                 ~USER_NS
161                 ~UTS_NS
162                 ~VETH
163                 ~!GRKERNSEC_CHROOT_MOUNT
164                 ~!GRKERNSEC_CHROOT_DOUBLE
165                 ~!GRKERNSEC_CHROOT_PIVOT
166                 ~!GRKERNSEC_CHROOT_CHMOD
167                 ~!GRKERNSEC_CHROOT_CAPS"
168
169         kernel_is lt 4 7 && use lxc && CONFIG_CHECK+="
170                 ~DEVPTS_MULTIPLE_INSTANCES"
171
172         use macvtap && CONFIG_CHECK+="
173                 ~MACVTAP"
174
175         use virt-network && CONFIG_CHECK+="
176                 ~BRIDGE_EBT_MARK_T
177                 ~BRIDGE_NF_EBTABLES
178                 ~NETFILTER_ADVANCED
179                 ~NETFILTER_XT_CONNMARK
180                 ~NETFILTER_XT_MARK
181                 ~NETFILTER_XT_TARGET_CHECKSUM
182                 ~IP_NF_FILTER
183                 ~IP_NF_MANGLE
184                 ~IP_NF_NAT
185                 ~IP_NF_TARGET_MASQUERADE
186                 ~IP6_NF_FILTER
187                 ~IP6_NF_MANGLE
188                 ~IP6_NF_NAT"
189         # Bandwidth Limiting Support
190         use virt-network && CONFIG_CHECK+="
191                 ~BRIDGE_EBT_T_NAT
192                 ~IP_NF_TARGET_REJECT
193                 ~NET_ACT_POLICE
194                 ~NET_CLS_FW
195                 ~NET_CLS_U32
196                 ~NET_SCH_HTB
197                 ~NET_SCH_INGRESS
198                 ~NET_SCH_SFQ"
199
200         # Handle specific kernel versions for different features
201         kernel_is lt 3 6 && CONFIG_CHECK+=" ~CGROUP_MEM_RES_CTLR"
202         if kernel_is ge 3 6; then
203                 CONFIG_CHECK+=" ~MEMCG ~MEMCG_SWAP "
204                 kernel_is lt 4 5 && CONFIG_CHECK+=" ~MEMCG_KMEM "
205         fi
206
207         ERROR_USER_NS="Optional depending on LXC configuration."
208
209         if [[ -n ${CONFIG_CHECK} ]]; then
210                 linux-info_pkg_setup
211         fi
212 }
213
214 src_prepare() {
215         touch "${S}/.mailmap"
216
217         default
218
219         if [[ ${PV} = *9999* ]]; then
220                 # Reinitialize submodules as this is required for gnulib's bootstrap
221                 git submodule init
222                 # git checkouts require bootstrapping to create the configure script.
223                 # Additionally the submodules must be cloned to the right locations
224                 # bug #377279
225                 ./bootstrap || die "bootstrap failed"
226                 (
227                     git submodule status .gnulib | awk '{ print $1 }'
228                     git hash-object bootstrap.conf
229                     git ls-tree -d HEAD gnulib/local | awk '{ print $3 }'
230                 ) >.git-module-status
231         fi
232
233         # Tweak the init script:
234         cp "${FILESDIR}/libvirtd.init-r18" "${S}/libvirtd.init" || die
235         sed -e "s/USE_FLAG_FIREWALLD/$(usex firewalld 'need firewalld' '')/" \
236                 -i "${S}/libvirtd.init" || die "sed failed"
237
238         eautoreconf
239 }
240
241 src_configure() {
242         local myeconfargs=(
243                 $(use_with apparmor)
244                 $(use_with apparmor apparmor-profiles)
245                 $(use_with audit)
246                 $(use_with caps capng)
247                 $(use_with dbus)
248                 $(use_with dtrace)
249                 $(use_with firewalld)
250                 $(use_with fuse)
251                 $(use_with glusterfs)
252                 $(use_with glusterfs storage-gluster)
253                 $(use_with iscsi storage-iscsi)
254                 $(use_with iscsi-direct storage-iscsi-direct)
255                 $(use_with libvirtd)
256                 $(use_with libssh)
257                 $(use_with lvm storage-lvm)
258                 $(use_with lvm storage-mpath)
259                 $(use_with lxc)
260                 $(use_with macvtap)
261                 $(use_enable nls)
262                 $(use_with numa numactl)
263                 $(use_with numa numad)
264                 $(use_with openvz)
265                 $(use_with parted storage-disk)
266                 $(use_with pcap libpcap)
267                 $(use_with phyp)
268                 $(use_with policykit polkit)
269                 $(use_with qemu)
270                 $(use_with qemu yajl)
271                 $(use_with rbd storage-rbd)
272                 $(use_with sasl)
273                 $(use_with selinux)
274                 $(use_with udev)
275                 $(use_with vepa virtualport)
276                 $(use_with virt-network network)
277                 $(use_with wireshark-plugins wireshark-dissector)
278                 $(use_with xen libxl)
279                 $(use_with zfs storage-zfs)
280
281                 --without-hal
282                 --without-netcf
283                 --without-sanlock
284
285                 --with-esx
286                 --with-init-script=systemd
287                 --with-qemu-group=$(usex caps qemu root)
288                 --with-qemu-user=$(usex caps qemu root)
289                 --with-remote
290                 --with-storage-fs
291                 --with-vmware
292
293                 --disable-static
294                 --disable-werror
295
296                 --localstatedir=/var
297         )
298
299         if use virtualbox && has_version app-emulation/virtualbox-ose; then
300                 myeconfargs+=( --with-vbox=/usr/lib/virtualbox-ose/ )
301         else
302                 myeconfargs+=( $(use_with virtualbox vbox) )
303         fi
304
305         econf "${myeconfargs[@]}"
306
307         if [[ ${PV} = *9999* ]]; then
308                 # Restore gnulib's config.sub and config.guess
309                 # bug #377279
310                 (cd .gnulib && git reset --hard > /dev/null)
311         fi
312 }
313
314 src_test() {
315         cd "${BUILD_DIR}"
316
317         # remove problematic tests, bug #591416, bug #591418
318         sed -i -e 's#commandtest$(EXEEXT) # #' \
319                 -e 's#virfirewalltest$(EXEEXT) # #' \
320                 -e 's#nwfilterebiptablestest$(EXEEXT) # #' \
321                 -e 's#nwfilterxml2firewalltest$(EXEEXT)$##' \
322                 tests/Makefile
323
324         export VIR_TEST_DEBUG=1
325         HOME="${T}" emake check || die "tests failed"
326 }
327
328 src_install() {
329         emake DESTDIR="${D}" \
330                 SYSTEMD_UNIT_DIR="$(systemd_get_systemunitdir)" install
331
332         find "${D}" -name '*.la' -delete || die
333
334         # Remove bogus, empty directories. They are either not used, or
335         # libvirtd is able to create them on demand
336         rm -rf "${D}"/etc/sysconfig
337         rm -rf "${D}"/var
338
339         newbashcomp "${S}/tools/bash-completion/vsh" virsh
340         bashcomp_alias virsh virt-admin
341
342         use libvirtd || return 0
343         # From here, only libvirtd-related instructions, be warned!
344
345         systemd_install_serviced \
346                 "${FILESDIR}"/libvirtd.service.conf libvirtd.service
347
348         systemd_newtmpfilesd "${FILESDIR}"/libvirtd.tmpfiles.conf libvirtd.conf
349
350         newinitd "${S}/libvirtd.init" libvirtd || die
351         newinitd "${FILESDIR}/libvirt-guests.init-r4" libvirt-guests || die
352         newinitd "${FILESDIR}/virtlockd.init-r1" virtlockd || die
353         newinitd "${FILESDIR}/virtlogd.init-r1" virtlogd || die
354
355         newconfd "${FILESDIR}/libvirtd.confd-r5" libvirtd || die
356         newconfd "${FILESDIR}/libvirt-guests.confd" libvirt-guests || die
357
358         DOC_CONTENTS=$(<"${FILESDIR}/README.gentoo-r2")
359         DISABLE_AUTOFORMATTING=true
360         readme.gentoo_create_doc
361 }
362
363 pkg_preinst() {
364         # we only ever want to generate this once
365         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
366                 rm -rf "${D}"/etc/libvirt/qemu/networks/default.xml
367         fi
368 }
369
370 pkg_postinst() {
371         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
372                 touch "${ROOT}"/etc/libvirt/qemu/networks/default.xml
373         fi
374
375         use libvirtd || return 0
376         # From here, only libvirtd-related instructions, be warned!
377
378         readme.gentoo_print_elog
379 }