1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 )
7 PYTHON_REQ_USE='ncurses,xml,threads'
9 inherit eutils bash-completion-r1 flag-o-matic multilib python-single-r1 toolchain-funcs versionator
12 MAJOR_V="$(get_version_component_range 1-2)"
14 if [[ $PV == *9999 ]]; then
18 EGIT_REPO_URI="git://xenbits.xen.org/${REPO}"
19 S="${WORKDIR}/${REPO}"
21 KEYWORDS="amd64 ~arm ~arm64 ~x86"
24 # xen-tools's gentoo patches tarball
26 # xen-tools's gentoo patches version which apply to this specific ebuild
28 # xen-tools ovmf's patches
32 # OVMF upstream 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d
35 [[ -n ${UPSTREAM_VER} ]] && \
36 UPSTREAM_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${P/-tools/}-upstream-patches-${UPSTREAM_VER}.tar.xz"
37 [[ -n ${SECURITY_VER} ]] && \
38 SECURITY_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-security-patches-${SECURITY_VER}.tar.xz"
39 [[ -n ${GENTOO_VER} ]] && \
40 GENTOO_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-gentoo-patches-${GENTOO_VER}.tar.xz"
41 [[ -n ${OVMF_VER} ]] && \
42 OVMF_PATCHSET_URI="https://dev.gentoo.org/~dlan/distfiles/${PN/-tools}-ovmf-patches-${OVMF_VER}.tar.xz"
44 SRC_URI="https://downloads.xenproject.org/release/xen/${MY_PV}/xen-${MY_PV}.tar.gz
45 http://code.coreboot.org/p/seabios/downloads/get/seabios-${SEABIOS_VER}.tar.gz
46 https://dev.gentoo.org/~dlan/distfiles/seabios-${SEABIOS_VER}.tar.gz
47 ovmf? ( https://dev.gentoo.org/~dlan/distfiles/ovmf-${OVMF_PV}.tar.bz2
48 ${OVMF_PATCHSET_URI} )
49 ${UPSTREAM_PATCHSET_URI}
50 ${SECURITY_PATCHSET_URI}
51 ${GENTOO_PATCHSET_URI}"
53 S="${WORKDIR}/xen-${MY_PV}"
56 DESCRIPTION="Xen tools including QEMU and xl"
57 HOMEPAGE="http://xen.org/"
58 DOCS=( README docs/README.xen-bugtool )
62 # Inclusion of IUSE ocaml on stabalizing requires maintainer of ocaml to (get off his hands and) make
63 # >=dev-lang/ocaml-4 stable
64 # Masked in profiles/eapi-5-files instead
65 IUSE="api custom-cflags debug doc flask hvm +qemu ocaml ovmf +qemu-traditional +pam python pygrub screen sdl static-libs system-qemu system-seabios"
68 ${PYTHON_REQUIRED_USE}
71 ^^ ( qemu system-qemu )"
83 DEPEND="${COMMON_DEPEND}
84 dev-python/lxml[${PYTHON_USEDEP}]
85 x86? ( sys-devel/dev86
87 pam? ( dev-python/pypam[${PYTHON_USEDEP}] )
88 api? ( dev-libs/libxml2
91 !arm? ( !arm64? ( dev-lang/nasm ) )
92 $(python_gen_impl_dep sqlite)
94 !amd64? ( >=sys-apps/dtc-1.4.0 )
95 amd64? ( sys-devel/bin86
96 system-seabios? ( sys-firmware/seabios )
104 dev-python/markdown[${PYTHON_USEDEP}]
105 dev-tex/latex2html[png,gif]
109 dev-texlive/texlive-latexextra
112 dev-texlive/texlive-latex
113 dev-texlive/texlive-pictures
114 dev-texlive/texlive-latexrecommended
116 hvm? ( x11-proto/xproto
120 sdl? ( media-libs/libsdl[X] )
122 system-qemu? ( app-emulation/qemu[xen] )
123 ocaml? ( dev-ml/findlib
124 >=dev-lang/ocaml-4 )"
126 RDEPEND="${COMMON_DEPEND}
127 sys-apps/iproute2[-minimal]
128 net-misc/bridge-utils
134 # hvmloader is used to bootstrap a fully virtualized kernel
135 # Approved by QA team in bug #144032
136 QA_WX_LOAD="usr/lib/xen/boot/hvmloader
137 usr/share/qemu-xen/qemu/s390-ccw.img"
143 export "CONFIG_LOMOUNT=y"
145 #bug 522642, disable compile tools/tests
146 export "CONFIG_TESTS=n"
148 if has_version dev-libs/libgcrypt:0; then
149 export "CONFIG_GCRYPT=y"
152 if [[ -z ${XEN_TARGET_ARCH} ]] ; then
153 if use x86 && use amd64; then
154 die "Confusion! Both x86 and amd64 are set in your use flags!"
156 export XEN_TARGET_ARCH="x86_32"
157 elif use amd64 ; then
158 export XEN_TARGET_ARCH="x86_64"
160 export XEN_TARGET_ARCH="arm32"
162 export XEN_TARGET_ARCH="arm64"
164 die "Unsupported architecture!"
170 # Upstream's patchset
171 if [[ -n ${UPSTREAM_VER} ]]; then
172 einfo "Try to apply Xen Upstream patch set"
173 EPATCH_SUFFIX="patch" \
176 epatch "${WORKDIR}"/patches-upstream
180 if [[ -n ${SECURITY_VER} ]]; then
181 einfo "Try to apply Xen Security patch set"
182 # apply main xen patches
183 # Two parallel systems, both work side by side
184 # Over time they may concdense into one. This will suffice for now
185 EPATCH_SUFFIX="patch"
188 source "${WORKDIR}"/patches-security/${PV}.conf || die
190 for i in ${XEN_SECURITY_MAIN}; do
191 epatch "${WORKDIR}"/patches-security/xen/$i
194 # apply qemu-xen/upstream patches
195 pushd "${S}"/tools/qemu-xen/ > /dev/null
196 for i in ${XEN_SECURITY_QEMUU}; do
197 epatch "${WORKDIR}"/patches-security/qemuu/$i
201 # apply qemu-traditional patches
202 pushd "${S}"/tools/qemu-xen-traditional/ > /dev/null
203 for i in ${XEN_SECURITY_QEMUT}; do
204 epatch "${WORKDIR}"/patches-security/qemut/$i
209 # move before Gentoo patch, one patch should apply to seabios, to fix gcc-4.5.x build err
210 mv ../seabios-${SEABIOS_VER} tools/firmware/seabios-dir-remote || die
211 pushd tools/firmware/ > /dev/null
212 ln -s seabios-dir-remote seabios-dir || die
216 if [[ -n ${GENTOO_VER} && -n ${GENTOO_GPV} ]]; then
217 einfo "Try to apply Gentoo specific patch set"
218 source "${FILESDIR}"/gentoo-patches.conf || die
219 _gpv=_gpv_${PN/-/_}_${PV//./}_${GENTOO_GPV}
220 for i in ${!_gpv}; do
221 EPATCH_SUFFIX="patch" \
223 epatch "${WORKDIR}"/patches-gentoo/$i
229 if [[ -n ${OVMF_VER} ]];then
230 einfo "Try to apply Ovmf patch set"
231 pushd "${WORKDIR}"/ovmf-*/ > /dev/null
232 EPATCH_SUFFIX="patch" \
235 epatch "${WORKDIR}"/patches-ovmf
238 mv ../ovmf-${OVMF_PV} tools/firmware/ovmf-dir-remote || die
241 mv tools/qemu-xen/qemu-bridge-helper.c tools/qemu-xen/xen-bridge-helper.c || die
243 # Fix texi2html build error with new texi2html, qemu.doc.html
244 sed -i -e "/texi2html -monolithic/s/-number//" tools/qemu-xen-traditional/Makefile || die
246 use api || sed -e "/SUBDIRS-\$(LIBXENAPI_BINDINGS) += libxen/d" -i tools/Makefile || die
247 sed -e 's:$(MAKE) PYTHON=$(PYTHON) subdirs-$@:LC_ALL=C "$(MAKE)" PYTHON=$(PYTHON) subdirs-$@:' \
248 -i tools/firmware/Makefile || die
250 # Drop .config, fixes to gcc-4.6
251 sed -e '/-include $(XEN_ROOT)\/.config/d' -i Config.mk || die "Couldn't drop"
253 # if the user *really* wants to use their own custom-cflags, let them
254 if use custom-cflags; then
255 einfo "User wants their own CFLAGS - removing defaults"
257 # try and remove all the default cflags
258 find "${S}" \( -name Makefile -o -name Rules.mk -o -name Config.mk \) \
260 -e 's/CFLAGS\(.*\)=\(.*\)-O3\(.*\)/CFLAGS\1=\2\3/' \
261 -e 's/CFLAGS\(.*\)=\(.*\)-march=i686\(.*\)/CFLAGS\1=\2\3/' \
262 -e 's/CFLAGS\(.*\)=\(.*\)-fomit-frame-pointer\(.*\)/CFLAGS\1=\2\3/' \
263 -e 's/CFLAGS\(.*\)=\(.*\)-g3*\s\(.*\)/CFLAGS\1=\2 \3/' \
264 -e 's/CFLAGS\(.*\)=\(.*\)-O2\(.*\)/CFLAGS\1=\2\3/' \
265 -i {} + || die "failed to re-set custom-cflags"
273 if ! use pygrub; then
274 sed -e '/^SUBDIRS-y += pygrub/d' -i tools/Makefile || die
277 if ! use python; then
278 sed -e '/^SUBDIRS-y += python$/d' -i tools/Makefile || die
282 sed -e '/SUBDIRS-$(CONFIG_X86) += firmware/d' -i tools/Makefile || die
284 elif ! use x86 && ! has x86 $(get_all_abis); then
285 mkdir -p "${WORKDIR}"/extra-headers/gnu || die
286 touch "${WORKDIR}"/extra-headers/gnu/stubs-32.h || die
287 export CPATH="${WORKDIR}"/extra-headers
292 sed -i -e "s:\$\$source/configure:\0 --enable-sdl:" \
293 tools/Makefile || die
295 sed -i -e "s:\${QEMU_ROOT\:\-\.}/configure:\0 --disable-sdl:" \
296 tools/qemu-xen-traditional/xen-setup || die
297 sed -i -e "s:\$\$source/configure:\0 --disable-sdl:" \
298 tools/Makefile || die
301 # Don't bother with qemu, only needed for fully virtualised guests
302 sed -e "s:install-tools\: tools/qemu-xen-traditional-dir:install-tools\: :g" -i Makefile || die
305 # Reset bash completion dir; Bug 472438
306 sed -e "s:^BASH_COMPLETION_DIR ?= \$(CONFIG_DIR)/bash_completion.d:BASH_COMPLETION_DIR ?= $(get_bashcompdir):" \
308 sed -i -e "/bash-completion/s/xl\.sh/xl/g" tools/libxl/Makefile || die
310 # xencommons, Bug #492332, sed lighter weight than patching
311 sed -e 's:\$QEMU_XEN -xen-domid:test -e "\$QEMU_XEN" \&\& &:' \
312 -i tools/hotplug/Linux/init.d/xencommons.in || die
314 # respect multilib, usr/lib/libcacard.so.0.0.0
315 sed -e "/^libdir=/s/\/lib/\/$(get_libdir)/" \
316 -i tools/qemu-xen/configure || die
318 #bug 518136, don't build 32bit exactuable for nomultilib profile
319 if [[ "${ARCH}" == 'amd64' ]] && ! has_multilib_profile; then
320 sed -i -e "/x86_emulator/d" tools/tests/Makefile || die
323 # use /var instead of /var/lib, consistat with previous ebuild
324 sed -i -e "/XEN_LOCK_DIR=/s/\$localstatedir/\/var/g" \
325 m4/paths.m4 configure tools/configure || die
326 # use /run instead of /var/run
327 sed -i -e "/XEN_RUN_DIR=/s/\$localstatedir//g" \
328 m4/paths.m4 configure tools/configure || die
330 # uncomment lines in xl.conf
331 sed -e 's:^#autoballoon=:autoballoon=:' \
332 -e 's:^#lockfile=:lockfile=:' \
333 -e 's:^#vif.default.script=:vif.default.script=:' \
334 -i tools/examples/xl.conf || die
336 # Bug #575868 converted to a sed statement, typo of one char
337 sed -e "s:granter’s:granter's:" -i xen/include/public/grant_table.h || die
343 local myconf="--prefix=${PREFIX}/usr \
344 --libdir=${PREFIX}/usr/$(get_libdir) \
345 --libexecdir=${PREFIX}/usr/libexec \
351 $(use_enable api xenapi) \
353 $(use_enable ocaml ocamltools) \
354 --with-xenstored=$(usex ocaml 'oxenstored' 'xenstored') \
357 use system-seabios && myconf+=" --with-system-seabios=/usr/share/seabios/bios.bin"
358 use system-qemu && myconf+=" --with-system-qemu=/usr/bin/qemu-system-x86_64"
359 use amd64 && myconf+=" $(use_enable qemu-traditional)"
364 export VARTEXFONTS="${T}/fonts"
366 use debug && myopt="${myopt} debug=y"
368 if test-flag-CC -fno-strict-overflow; then
369 append-flags -fno-strict-overflow
372 emake V=1 CC="$(tc-getCC)" LD="$(tc-getLD)" AR="$(tc-getAR)" RANLIB="$(tc-getRANLIB)" -C tools ${myopt}
374 use doc && emake -C docs txt html
375 emake -C docs man-pages
379 # Override auto-detection in the build system, bug #382573
380 export INITD_DIR=/tmp/init.d
381 export CONFIG_LEAF_DIR=../tmp/default
383 # Let the build system compile installed Python modules.
384 local PYTHONDONTWRITEBYTECODE
385 export PYTHONDONTWRITEBYTECODE
387 emake DESTDIR="${ED}" DOCDIR="/usr/share/doc/${PF}" \
388 XEN_PYTHON_NATIVE_INSTALL=y install-tools
390 # Fix the remaining Python shebangs.
391 python_fix_shebang "${D}"
393 # Remove RedHat-specific stuff
394 rm -rf "${D}"tmp || die
397 emake DESTDIR="${D}" DOCDIR="/usr/share/doc/${PF}" install-docs
402 [ -d "${D}"/usr/share/doc/xen ] && mv "${D}"/usr/share/doc/xen/* "${D}"/usr/share/doc/${PF}/html
405 rm -rf "${D}"/usr/share/doc/xen/
408 newconfd "${FILESDIR}"/xendomains.confd xendomains
409 newconfd "${FILESDIR}"/xenstored.confd xenstored
410 newconfd "${FILESDIR}"/xenconsoled.confd xenconsoled
411 newinitd "${FILESDIR}"/xendomains.initd-r2 xendomains
412 newinitd "${FILESDIR}"/xenstored.initd xenstored
413 newinitd "${FILESDIR}"/xenconsoled.initd xenconsoled
414 newinitd "${FILESDIR}"/xencommons.initd xencommons
415 newconfd "${FILESDIR}"/xencommons.confd xencommons
416 newinitd "${FILESDIR}"/xenqemudev.initd xenqemudev
417 newconfd "${FILESDIR}"/xenqemudev.confd xenqemudev
420 cat "${FILESDIR}"/xendomains-screen.confd >> "${D}"/etc/conf.d/xendomains || die
421 cp "${FILESDIR}"/xen-consoles.logrotate "${D}"/etc/xen/ || die
422 keepdir /var/log/xen-consoles
425 # For -static-libs wrt Bug 384355
426 if ! use static-libs; then
427 rm -f "${D}"usr/$(get_libdir)/*.a "${D}"usr/$(get_libdir)/ocaml/*/*.a
431 keepdir /etc/xen/auto
433 # Remove files failing QA AFTER emake installs them, avoiding seeking absent files
434 find "${D}" \( -name openbios-sparc32 -o -name openbios-sparc64 \
435 -o -name openbios-ppc -o -name palcode-clipper \) -delete || die
439 elog "Official Xen Guide and the offical wiki page:"
440 elog "https://wiki.gentoo.org/wiki/Xen"
441 elog "http://wiki.xen.org/wiki/Main_Page"
443 elog "Recommended to utilise the xencommons script to config sytem At boot"
444 elog "Add by use of rc-update on completion of the install"
448 elog "HVM (VT-x and AMD-V) support has been disabled. If you need hvm"
449 elog "support enable the hvm use flag."
450 elog "An x86 or amd64 system is required to build HVM support."
454 elog "The qemu-bridge-helper is renamed to the xen-bridge-helper in the in source"
455 elog "build of qemu. This allows for app-emulation/qemu to be emerged concurrently"
456 elog "with the qemu capable xen. It is up to the user to distinguish between and utilise"
457 elog "the qemu-bridge-helper and the xen-bridge-helper. File bugs of any issues that arise"