1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{6,7,8} )
7 PYTHON_REQ_USE='ncurses,xml,threads(+)'
9 inherit bash-completion-r1 flag-o-matic multilib python-single-r1 toolchain-funcs
13 if [[ $PV == *9999 ]]; then
16 EGIT_REPO_URI="git://xenbits.xen.org/${REPO}"
17 S="${WORKDIR}/${REPO}"
19 KEYWORDS="~amd64 ~arm ~arm64 ~x86"
22 # xen-tools's gentoo patches tarball
24 # xen-tools's gentoo patches version which apply to this specific ebuild
26 # xen-tools ovmf's patches
30 EDK2_COMMIT="20d2e5a125e34fc8501026613a71549b2a1a3e54"
31 EDK2_OPENSSL_VERSION="1_1_1b"
32 EDK2_SOFTFLOAT_COMMIT="b64af41c3276f97f0e181920400ee056b9c88037"
33 IPXE_COMMIT="1dd56dbd11082fb622c2ed21cfaced4f47d798a6"
35 [[ -n ${UPSTREAM_VER} ]] && \
36 UPSTREAM_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${P/-tools/}-upstream-patches-${UPSTREAM_VER}.tar.xz
37 https://github.com/hydrapolic/gentoo-dist/raw/master/xen/${P/-tools/}-upstream-patches-${UPSTREAM_VER}.tar.xz"
38 [[ -n ${SECURITY_VER} ]] && \
39 SECURITY_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-security-patches-${SECURITY_VER}.tar.xz"
40 [[ -n ${GENTOO_VER} ]] && \
41 GENTOO_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-gentoo-patches-${GENTOO_VER}.tar.xz
42 https://github.com/hydrapolic/gentoo-dist/raw/master/xen/${PN/-tools/}-gentoo-patches-${GENTOO_VER}.tar.xz"
43 [[ -n ${OVMF_VER} ]] && \
44 OVMF_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-ovmf-patches-${OVMF_VER}.tar.xz"
46 SRC_URI="https://downloads.xenproject.org/release/xen/${MY_PV}/xen-${MY_PV}.tar.gz
47 https://github.com/qemu/seabios/archive/rel-${SEABIOS_VER}.tar.gz -> seabios-${SEABIOS_VER}.tar.gz
48 ipxe? ( http://xenbits.xen.org/xen-extfiles/ipxe-git-${IPXE_COMMIT}.tar.gz )
49 ovmf? ( https://github.com/tianocore/edk2/archive/${EDK2_COMMIT}.tar.gz -> edk2-${EDK2_COMMIT}.tar.gz
50 https://github.com/openssl/openssl/archive/OpenSSL_${EDK2_OPENSSL_VERSION}.tar.gz
51 https://github.com/ucb-bar/berkeley-softfloat-3/archive/${EDK2_SOFTFLOAT_COMMIT}.tar.gz -> berkeley-softfloat-${EDK2_SOFTFLOAT_COMMIT}.tar.gz
52 ${OVMF_PATCHSET_URI} )
53 ${UPSTREAM_PATCHSET_URI}
54 ${SECURITY_PATCHSET_URI}
55 ${GENTOO_PATCHSET_URI}"
57 S="${WORKDIR}/xen-${MY_PV}"
60 DESCRIPTION="Xen tools including QEMU and xl"
61 HOMEPAGE="https://www.xenproject.org"
65 SLOT="0/$(ver_cut 1-2)"
66 # Inclusion of IUSE ocaml on stabalizing requires maintainer of ocaml to (get off his hands and) make
67 # >=dev-lang/ocaml-4 stable
68 # Masked in profiles/eapi-5-files instead
69 IUSE="api debug doc flask +hvm +ipxe ocaml ovmf +pam pygrub python +qemu +qemu-traditional +rombios screen sdl static-libs system-ipxe system-qemu system-seabios"
72 ${PYTHON_REQUIRED_USE}
77 system-ipxe? ( rombios )
78 ?? ( ipxe system-ipxe )
79 ?? ( qemu system-qemu )"
92 DEPEND="${COMMON_DEPEND}
93 >=sys-kernel/linux-headers-4.11
94 $(python_gen_cond_dep '
95 dev-python/lxml[${PYTHON_MULTI_USEDEP}]
96 pam? ( dev-python/pypam[${PYTHON_MULTI_USEDEP}] )
98 x86? ( sys-devel/dev86
99 system-ipxe? ( sys-firmware/ipxe[qemu] )
101 api? ( dev-libs/libxml2
105 !arm? ( !arm64? ( dev-lang/nasm ) )
106 $(python_gen_impl_dep sqlite)
108 !amd64? ( >=sys-apps/dtc-1.4.0 )
109 amd64? ( sys-power/iasl
110 system-seabios? ( sys-firmware/seabios )
111 system-ipxe? ( sys-firmware/ipxe[qemu] )
112 rombios? ( sys-devel/bin86 sys-devel/dev86 ) )
116 app-text/ghostscript-gpl
118 $(python_gen_cond_dep '
119 dev-python/markdown[${PYTHON_MULTI_USEDEP}]
121 dev-texlive/texlive-latexextra
124 hvm? ( x11-base/xorg-proto )
130 media-libs/libsdl2[X]
133 system-qemu? ( app-emulation/qemu[xen] )
134 ocaml? ( dev-ml/findlib
136 python? ( >=dev-lang/swig-4.0.0 )"
138 RDEPEND="${COMMON_DEPEND}
139 sys-apps/iproute2[-minimal]
140 net-misc/bridge-utils
146 # hvmloader is used to bootstrap a fully virtualized kernel
147 # Approved by QA team in bug #144032
149 usr/libexec/xen/boot/hvmloader
150 usr/share/qemu-xen/qemu/hppa-firmware.img
151 usr/share/qemu-xen/qemu/s390-ccw.img
152 usr/share/qemu-xen/qemu/u-boot.e500
156 usr/libexec/xen/bin/elf2dmp
157 usr/libexec/xen/bin/ivshmem-client
158 usr/libexec/xen/bin/ivshmem-server
159 usr/libexec/xen/bin/qemu-edid
160 usr/libexec/xen/bin/qemu-img
161 usr/libexec/xen/bin/qemu-io
162 usr/libexec/xen/bin/qemu-keymap
163 usr/libexec/xen/bin/qemu-nbd
164 usr/libexec/xen/bin/qemu-pr-helper
165 usr/libexec/xen/bin/qemu-system-i386
166 usr/libexec/xen/bin/virtfs-proxy-helper
167 usr/libexec/xen/libexec/xen-bridge-helper
168 usr/share/qemu-xen/qemu/s390-ccw.img
169 usr/share/qemu-xen/qemu/s390-netboot.img
170 usr/share/qemu-xen/qemu/u-boot.e500
177 export "CONFIG_LOMOUNT=y"
179 #bug 522642, disable compile tools/tests
180 export "CONFIG_TESTS=n"
182 if [[ -z ${XEN_TARGET_ARCH} ]] ; then
183 if use x86 && use amd64; then
184 die "Confusion! Both x86 and amd64 are set in your use flags!"
186 export XEN_TARGET_ARCH="x86_32"
187 elif use amd64 ; then
188 export XEN_TARGET_ARCH="x86_64"
190 export XEN_TARGET_ARCH="arm32"
192 export XEN_TARGET_ARCH="arm64"
194 die "Unsupported architecture!"
202 # Upstream's patchset
203 if [[ -n ${UPSTREAM_VER} ]]; then
204 einfo "Try to apply Xen Upstream patch set"
205 eapply "${WORKDIR}"/patches-upstream
209 if [[ -n ${SECURITY_VER} ]]; then
210 einfo "Try to apply Xen Security patch set"
211 # apply main xen patches
212 # Two parallel systems, both work side by side
213 # Over time they may concdense into one. This will suffice for now
214 EPATCH_SUFFIX="patch"
217 source "${WORKDIR}"/patches-security/${PV}.conf || die
219 for i in ${XEN_SECURITY_MAIN}; do
220 eapply "${WORKDIR}"/patches-security/xen/$i
223 # apply qemu-xen/upstream patches
224 pushd "${S}"/tools/qemu-xen/ > /dev/null
225 for i in ${XEN_SECURITY_QEMUU}; do
226 eapply "${WORKDIR}"/patches-security/qemuu/$i
230 # apply qemu-traditional patches
231 pushd "${S}"/tools/qemu-xen-traditional/ > /dev/null
232 for i in ${XEN_SECURITY_QEMUT}; do
233 eapply "${WORKDIR}"/patches-security/qemut/$i
238 # move before Gentoo patch, one patch should apply to seabios, to fix gcc-4.5.x build err
239 mv ../seabios-rel-${SEABIOS_VER} tools/firmware/seabios-dir-remote || die
240 pushd tools/firmware/ > /dev/null
241 ln -s seabios-dir-remote seabios-dir || die
245 if [[ -n ${GENTOO_VER} && -n ${GENTOO_GPV} ]]; then
246 einfo "Try to apply Gentoo specific patch set"
247 source "${FILESDIR}"/gentoo-patches.conf || die
248 _gpv=_gpv_${PN/-/_}_${PV//./}_${GENTOO_GPV}
249 for i in ${!_gpv}; do
250 eapply "${WORKDIR}"/patches-gentoo/$i
256 if [[ -n ${OVMF_VER} ]];then
257 einfo "Try to apply Ovmf patch set"
258 pushd "${WORKDIR}"/edk2-*/ > /dev/null
259 eapply "${WORKDIR}"/patches-ovmf
262 mv ../edk2-${EDK2_COMMIT} tools/firmware/ovmf-dir-remote || die
263 rm -r tools/firmware/ovmf-dir-remote/CryptoPkg/Library/OpensslLib/openssl || die
264 rm -r tools/firmware/ovmf-dir-remote/ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 || die
265 mv ../openssl-OpenSSL_${EDK2_OPENSSL_VERSION} tools/firmware/ovmf-dir-remote/CryptoPkg/Library/OpensslLib/openssl || die
266 mv ../berkeley-softfloat-3-${EDK2_SOFTFLOAT_COMMIT} tools/firmware/ovmf-dir-remote/ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 || die
267 cp tools/firmware/ovmf-makefile tools/firmware/ovmf-dir-remote/Makefile || die
272 cp "${DISTDIR}/ipxe-git-${IPXE_COMMIT}.tar.gz" tools/firmware/etherboot/_ipxe.tar.gz || die
275 cp "${WORKDIR}/patches-gentoo/xen-tools-4.13.0-ipxe-gcc10.patch" tools/firmware/etherboot/patches/ipxe-gcc10.patch || die
276 echo ipxe-gcc10.patch >> tools/firmware/etherboot/patches/series || die
279 mv tools/qemu-xen/qemu-bridge-helper.c tools/qemu-xen/xen-bridge-helper.c || die
281 # Fix texi2html build error with new texi2html, qemu.doc.html
282 sed -i -e "/texi2html -monolithic/s/-number//" tools/qemu-xen-traditional/Makefile || die
284 use api || sed -e "/SUBDIRS-\$(LIBXENAPI_BINDINGS) += libxen/d" -i tools/Makefile || die
285 sed -e 's:$(MAKE) PYTHON=$(PYTHON) subdirs-$@:LC_ALL=C "$(MAKE)" PYTHON=$(PYTHON) subdirs-$@:' \
286 -i tools/firmware/Makefile || die
288 # Drop .config, fixes to gcc-4.6
289 sed -e '/-include $(XEN_ROOT)\/.config/d' -i Config.mk || die "Couldn't drop"
297 if ! use pygrub; then
298 sed -e '/^SUBDIRS-y += pygrub/d' -i tools/Makefile || die
301 if ! use python; then
302 sed -e '/^SUBDIRS-y += python$/d' -i tools/Makefile || die
306 sed -e '/SUBDIRS-$(CONFIG_X86) += firmware/d' -i tools/Makefile || die
308 elif ! use x86 && ! has x86 $(get_all_abis); then
309 mkdir -p "${WORKDIR}"/extra-headers/gnu || die
310 touch "${WORKDIR}"/extra-headers/gnu/stubs-32.h || die
311 export CPATH="${WORKDIR}"/extra-headers
316 sed -i -e "s:\$\$source/configure:\0 --enable-sdl:" \
317 tools/Makefile || die
319 sed -i -e "s:\${QEMU_ROOT\:\-\.}/configure:\0 --disable-sdl:" \
320 tools/qemu-xen-traditional/xen-setup || die
321 sed -i -e "s:\$\$source/configure:\0 --disable-sdl:" \
322 tools/Makefile || die
325 # Don't bother with qemu, only needed for fully virtualised guests
326 sed -i '/SUBDIRS-$(CONFIG_QEMU_XEN)/s/^/#/g' tools/Makefile || die
329 # Reset bash completion dir; Bug 472438
330 sed -e "s:^BASH_COMPLETION_DIR ?= \$(CONFIG_DIR)/bash_completion.d:BASH_COMPLETION_DIR ?= $(get_bashcompdir):" \
332 sed -i -e "/bash-completion/s/xl\.sh/xl/g" tools/libxl/Makefile || die
334 # xencommons, Bug #492332, sed lighter weight than patching
335 sed -e 's:\$QEMU_XEN -xen-domid:test -e "\$QEMU_XEN" \&\& &:' \
336 -i tools/hotplug/Linux/init.d/xencommons.in || die
339 sed -e '/Usage/s/\$//g' \
340 -i tools/hotplug/Linux/init.d/xendriverdomain.in || die
342 # respect multilib, usr/lib/libcacard.so.0.0.0
343 sed -e "/^libdir=/s/\/lib/\/$(get_libdir)/" \
344 -i tools/qemu-xen/configure || die
346 #bug 518136, don't build 32bit exactuable for nomultilib profile
347 if [[ "${ARCH}" == 'amd64' ]] && ! has_multilib_profile; then
348 sed -i -e "/x86_emulator/d" tools/tests/Makefile || die
351 # uncomment lines in xl.conf
352 sed -e 's:^#autoballoon=:autoballoon=:' \
353 -e 's:^#lockfile=:lockfile=:' \
354 -e 's:^#vif.default.script=:vif.default.script=:' \
355 -i tools/examples/xl.conf || die
357 # disable capstone (Bug #673474)
358 sed -e "s:\$\$source/configure:\0 --disable-capstone:" \
359 -i tools/Makefile || die
362 sed -e "s:\$\$source/configure:\0 --disable-glusterfs:" \
363 -i tools/Makefile || die
369 local myconf="--prefix=${PREFIX}/usr \
370 --libdir=${PREFIX}/usr/$(get_libdir) \
371 --libexecdir=${PREFIX}/usr/libexec \
372 --localstatedir=${EPREFIX}/var \
377 $(use_enable api xenapi) \
379 $(usex system-ipxe '--with-system-ipxe=/usr/share/ipxe' '') \
380 $(use_enable ocaml ocamltools) \
383 $(use_enable rombios) \
384 --with-xenstored=$(usex ocaml 'oxenstored' 'xenstored') \
387 use system-seabios && myconf+=" --with-system-seabios=/usr/share/seabios/bios.bin"
388 use system-qemu && myconf+=" --with-system-qemu=/usr/bin/qemu-system-x86_64"
389 use amd64 && myconf+=" $(use_enable qemu-traditional)"
390 tc-ld-disable-gold # Bug 669570
396 use debug && myopt="${myopt} debug=y"
397 use python && myopt="${myopt} XENSTAT_PYTHON_BINDINGS=y"
399 if test-flag-CC -fno-strict-overflow; then
400 append-flags -fno-strict-overflow
403 emake CC="$(tc-getCC)" LD="$(tc-getLD)" AR="$(tc-getAR)" RANLIB="$(tc-getRANLIB)" build-tools ${myopt}
408 emake -C docs man-pages
413 # Override auto-detection in the build system, bug #382573
414 export INITD_DIR=/tmp/init.d
415 export CONFIG_LEAF_DIR=../tmp/default
417 # Let the build system compile installed Python modules.
418 local PYTHONDONTWRITEBYTECODE
419 export PYTHONDONTWRITEBYTECODE
421 emake DESTDIR="${ED}" DOCDIR="/usr/share/doc/${PF}" \
422 XEN_PYTHON_NATIVE_INSTALL=y install-tools
425 rm -rv "${ED}/var/run" || die
427 # Fix the remaining Python shebangs.
428 python_fix_shebang "${D}"
430 # Remove RedHat-specific stuff
431 rm -rf "${D}"/tmp || die
434 emake DESTDIR="${D}" DOCDIR="/usr/share/doc/${PF}" install-docs
435 dodoc -r docs/{pdf,txt}
437 emake -C docs DESTDIR="${D}" DOCDIR="/usr/share/doc/${PF}" install-man-pages # Bug 668032
441 newconfd "${FILESDIR}"/xendomains.confd xendomains
442 newconfd "${FILESDIR}"/xenstored.confd xenstored
443 newconfd "${FILESDIR}"/xenconsoled.confd xenconsoled
444 newinitd "${FILESDIR}"/xendomains.initd-r2 xendomains
445 newinitd "${FILESDIR}"/xenstored.initd-r1 xenstored
446 newinitd "${FILESDIR}"/xenconsoled.initd xenconsoled
447 newinitd "${FILESDIR}"/xencommons.initd xencommons
448 newconfd "${FILESDIR}"/xencommons.confd xencommons
449 newinitd "${FILESDIR}"/xenqemudev.initd xenqemudev
450 newconfd "${FILESDIR}"/xenqemudev.confd xenqemudev
451 newinitd "${FILESDIR}"/xen-watchdog.initd xen-watchdog
454 cat "${FILESDIR}"/xendomains-screen.confd >> "${D}"/etc/conf.d/xendomains || die
455 cp "${FILESDIR}"/xen-consoles.logrotate "${D}"/etc/xen/ || die
456 keepdir /var/log/xen-consoles
459 # For -static-libs wrt Bug 384355
460 if ! use static-libs; then
461 rm -f "${D}"/usr/$(get_libdir)/*.a "${D}"/usr/$(get_libdir)/ocaml/*/*.a
465 keepdir /etc/xen/auto
467 # Remove files failing QA AFTER emake installs them, avoiding seeking absent files
468 find "${D}" \( -name openbios-sparc32 -o -name openbios-sparc64 \
469 -o -name openbios-ppc -o -name palcode-clipper \) -delete || die
471 keepdir /var/lib/xen/dump
472 keepdir /var/lib/xen/xenpaging
473 keepdir /var/lib/xenstored
477 python_domodule "${S}/tools/xenstat/libxenstat/bindings/swig/python/xenstat.py"
478 python_domodule "${S}/tools/xenstat/libxenstat/bindings/swig/python/_xenstat.so"
485 elog "Official Xen Guide and the offical wiki page:"
486 elog "https://wiki.gentoo.org/wiki/Xen"
487 elog "https://wiki.xen.org/wiki/Main_Page"
489 elog "Recommended to utilise the xencommons script to config system at boot"
490 elog "Add by use of rc-update on completion of the install"
494 elog "HVM (VT-x and AMD-V) support has been disabled. If you need hvm"
495 elog "support enable the hvm use flag."
496 elog "An x86 or amd64 system is required to build HVM support."
500 elog "The qemu-bridge-helper is renamed to the xen-bridge-helper in the in source"
501 elog "build of qemu. This allows for app-emulation/qemu to be emerged concurrently"
502 elog "with the qemu capable xen. It is up to the user to distinguish between and utilise"
503 elog "the qemu-bridge-helper and the xen-bridge-helper. File bugs of any issues that arise"