1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 PYTHON_COMPAT=( python2_7 )
8 PYTHON_REQ_USE="ncurses,readline"
10 inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
11 user udev fcaps readme.gentoo pax-utils
15 if [[ ${PV} = *9999* ]]; then
16 EGIT_REPO_URI="git://git.qemu.org/qemu.git"
20 SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2
22 https://dev.gentoo.org/~cardoe/distfiles/${P}-${BACKPORTS}.tar.xz}"
23 KEYWORDS="amd64 ~ppc ~ppc64 x86 ~x86-fbsd"
26 DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
27 HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
29 LICENSE="GPL-2 LGPL-2 BSD-2"
31 IUSE="accessibility +aio alsa bluetooth +caps +curl debug +fdt glusterfs \
32 gtk gtk2 infiniband iscsi +jpeg \
33 kernel_linux kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs
34 +png pulseaudio python \
35 rbd sasl +seccomp sdl sdl2 selinux smartcard snappy spice ssh static static-softmmu
36 static-user systemtap tci test +threads tls usb usbredir +uuid vde +vhost-net \
37 virtfs +vnc vte xattr xen xfs"
39 COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel mips
40 mips64 mips64el mipsel or32 ppc ppc64 s390x sh4 sh4eb sparc sparc64 unicore32
42 IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS} lm32 moxie ppcemb tricore xtensa xtensaeb"
43 IUSE_USER_TARGETS="${COMMON_TARGETS} armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus"
45 use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
46 use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
47 IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
49 # Allow no targets to be built so that people can get a tools-only build.
50 # Block USE flag configurations known to not work.
51 REQUIRED_USE="${PYTHON_REQUIRED_USE}
53 qemu_softmmu_targets_arm? ( fdt )
54 qemu_softmmu_targets_microblaze? ( fdt )
55 qemu_softmmu_targets_ppc? ( fdt )
56 qemu_softmmu_targets_ppc64? ( fdt )
58 static? ( static-softmmu static-user )
59 static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl !gtk !gtk2 )
63 # Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
65 # The attr lib isn't always linked in (although the USE flag is always
66 # respected). This is because qemu supports using the C library's API
67 # when available rather than always using the extranl library.
68 COMMON_LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
69 sys-libs/zlib[static-libs(+)]
70 xattr? ( sys-apps/attr[static-libs(+)] )"
71 SOFTMMU_LIB_DEPEND="${COMMON_LIB_DEPEND}
72 >=x11-libs/pixman-0.28.0[static-libs(+)]
73 accessibility? ( app-accessibility/brltty[static-libs(+)] )
74 aio? ( dev-libs/libaio[static-libs(+)] )
75 alsa? ( >=media-libs/alsa-lib-1.0.13 )
76 bluetooth? ( net-wireless/bluez )
77 caps? ( sys-libs/libcap-ng[static-libs(+)] )
78 curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
79 fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
80 glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
84 vte? ( x11-libs/vte:0 )
88 vte? ( x11-libs/vte:2.90 )
91 infiniband? ( sys-infiniband/librdmacm:=[static-libs(+)] )
92 iscsi? ( net-libs/libiscsi )
93 jpeg? ( virtual/jpeg:=[static-libs(+)] )
94 lzo? ( dev-libs/lzo:2[static-libs(+)] )
95 ncurses? ( sys-libs/ncurses:0=[static-libs(+)] )
96 nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
97 numa? ( sys-process/numactl[static-libs(+)] )
100 media-libs/libepoxy[static-libs(+)]
101 media-libs/mesa[static-libs(+)]
102 media-libs/mesa[egl,gles2]
104 png? ( media-libs/libpng:0=[static-libs(+)] )
105 pulseaudio? ( media-sound/pulseaudio )
106 rbd? ( sys-cluster/ceph[static-libs(+)] )
107 sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
111 >=media-libs/libsdl-1.2.11[static-libs(+)]
114 media-libs/libsdl2[X]
115 media-libs/libsdl2[static-libs(+)]
118 seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
119 smartcard? ( dev-libs/nss !app-emulation/libcacard )
120 snappy? ( app-arch/snappy[static-libs(+)] )
122 >=app-emulation/spice-protocol-0.12.3
123 >=app-emulation/spice-0.12.0[static-libs(+)]
125 ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
126 tls? ( net-libs/gnutls[static-libs(+)] )
127 usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
128 usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
129 uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
130 vde? ( net-misc/vde[static-libs(+)] )
131 virtfs? ( sys-libs/libcap )
132 xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
133 USER_LIB_DEPEND="${COMMON_LIB_DEPEND}"
134 X86_FIRMWARE_DEPEND="
135 >=sys-firmware/ipxe-1.0.0_p20130624
136 pin-upstream-blobs? (
137 ~sys-firmware/seabios-1.8.2
138 ~sys-firmware/sgabios-0.1_pre8
139 ~sys-firmware/vgabios-0.7a
141 !pin-upstream-blobs? (
147 !static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND//\[static-libs(+)]} ) " ${use_softmmu_targets}) )
148 !static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND//\[static-libs(+)]} ) " ${use_user_targets}) )
149 qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
150 qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
151 python? ( ${PYTHON_DEPS} )
152 systemtap? ( dev-util/systemtap )
153 xen? ( app-emulation/xen-tools:= )"
159 kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
160 gtk? ( nls? ( sys-devel/gettext ) )
161 static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND} ) " ${use_softmmu_targets}) )
162 static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND} ) " ${use_user_targets}) )
168 selinux? ( sec-policy/selinux-qemu )
171 STRIP_MASK="/usr/share/qemu/palcode-clipper"
174 usr/share/qemu/openbios-ppc
175 usr/share/qemu/openbios-sparc64
176 usr/share/qemu/openbios-sparc32
177 usr/share/qemu/palcode-clipper
178 usr/share/qemu/s390-ccw.img
179 usr/share/qemu/u-boot.e500
182 QA_WX_LOAD="usr/bin/qemu-i386
188 usr/bin/qemu-microblaze
189 usr/bin/qemu-microblazeel
195 usr/bin/qemu-ppc64abi32
201 usr/bin/qemu-sparc32plus
203 usr/bin/qemu-unicore32"
205 DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure
206 you have the kernel module loaded before running kvm. The easiest way to
207 ensure that the kernel module is loaded is to load it on boot.\n
208 For AMD CPUs the module is called 'kvm-amd'\n
209 For Intel CPUs the module is called 'kvm-intel'\n
210 Please review /etc/conf.d/modules for how to load these\n\n
211 Make sure your user is in the 'kvm' group\n
212 Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."
215 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
216 use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
217 use qemu_softmmu_targets_s390x; then
225 if use kernel_linux && kernel_is lt 2 6 25; then
226 eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
227 elif use kernel_linux; then
228 if ! linux_config_exists; then
229 eerror "Unable to check your kernel for KVM support"
231 CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
232 ERROR_KVM="You must enable KVM in your kernel to continue"
233 ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
234 ERROR_KVM_AMD+=" your kernel configuration."
235 ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
236 ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
237 ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
238 ERROR_TUN+=" into your kernel or loaded as a module to use the"
239 ERROR_TUN+=" virtual network device if using -net tap."
240 ERROR_BRIDGE="You will also need support for 802.1d"
241 ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
242 use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
243 ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
244 ERROR_VHOST_NET+=" support"
246 if use amd64 || use x86 || use amd64-linux || use x86-linux; then
247 CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
250 use python && CONFIG_CHECK+=" ~DEBUG_FS"
251 ERROR_DEBUG_FS="debugFS support required for kvm_stat"
253 # Now do the actual checks setup above
258 if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
259 eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
260 eerror "instances are still pointing to it. Please update your"
261 eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
262 eerror "and the right system binary (e.g. qemu-system-x86_64)."
263 die "update your virt configs to not use qemu-kvm"
271 # Sanity check to make sure target lists are kept up-to-date.
274 local detected sorted
276 pushd "${S}"/default-configs >/dev/null || die
278 # Force C locale until glibc is updated. #564936
279 detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
280 sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
281 if [[ ${sorted} != "${detected}" ]] ; then
282 eerror "The ebuild needs to be kept in sync."
283 eerror "${var}: ${sorted}"
284 eerror "$(printf '%-*s' ${#var} configure): ${detected}"
285 die "sync ${var} to the list of targets"
292 check_targets IUSE_SOFTMMU_TARGETS softmmu
293 check_targets IUSE_USER_TARGETS linux-user
295 # Alter target makefiles to accept CFLAGS set via flag-o
297 -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
298 Makefile Makefile.target || die
300 # Cheap hack to disable gettext .mo generation.
301 use nls || rm -f po/*.po
303 epatch "${FILESDIR}"/qemu-1.7.0-cflags.patch
304 epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-{7504,7512}.patch #567144
305 epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-8345.patch #566792
306 epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-8504.patch #567828
307 epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-7549.patch #568214
308 epatch "${FILESDIR}"/${PN}-2.4-mips-* #563162
309 [[ -n ${BACKPORTS} ]] && \
310 EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
313 # Fix ld and objcopy being called directly
314 tc-export AR LD OBJCOPY
323 # configures qemu based on the build directory and the build type
326 qemu_src_configure() {
327 debug-print-function ${FUNCNAME} "$@"
330 local builddir="${S}/${buildtype}-build"
331 local static_flag="static-${buildtype}"
338 --libdir=/usr/$(get_libdir)
339 --docdir=/usr/share/doc/${PF}/html
341 --disable-guest-agent
347 --host-cc="$(tc-getBUILD_CC)"
348 $(use_enable debug debug-info)
349 $(use_enable debug debug-tcg)
351 $(use_enable tci tcg-interpreter)
352 $(use_enable xattr attr)
355 # Disable options not used by user targets as the default configure
356 # options will autoprobe and try to link in a bunch of unused junk.
358 if [[ ${buildtype} == "user" ]] ; then
359 echo "--disable-${2:-$1}"
365 $(conf_softmmu accessibility brlapi)
366 $(conf_softmmu aio linux-aio)
367 $(conf_softmmu bluetooth bluez)
368 $(conf_softmmu caps cap-ng)
371 $(conf_softmmu glusterfs)
373 $(conf_softmmu infiniband rdma)
374 $(conf_softmmu iscsi libiscsi)
375 $(conf_softmmu jpeg vnc-jpeg)
376 $(conf_softmmu kernel_linux kvm)
378 $(conf_softmmu ncurses curses)
379 $(conf_softmmu nfs libnfs)
381 $(conf_softmmu opengl)
382 $(conf_softmmu png vnc-png)
384 $(conf_softmmu sasl vnc-sasl)
386 $(conf_softmmu seccomp)
387 $(conf_softmmu smartcard smartcard-nss)
388 $(conf_softmmu snappy)
389 $(conf_softmmu spice)
390 $(conf_softmmu ssh libssh2)
391 $(conf_softmmu tls vnc-tls)
392 $(conf_softmmu usb libusb)
393 $(conf_softmmu usbredir usb-redir)
396 $(conf_softmmu vhost-net)
397 $(conf_softmmu virtfs)
401 $(conf_softmmu xen xen-pci-passthrough)
402 $(conf_softmmu xfs xfsctl)
416 local audio_opts="oss"
417 use alsa && audio_opts="alsa,${audio_opts}"
418 use sdl && audio_opts="sdl,${audio_opts}"
419 use pulseaudio && audio_opts="pa,${audio_opts}"
425 --audio-drv-list="${audio_opts}"
427 use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
428 use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
440 local targets="${buildtype}_targets"
441 [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
443 # Add support for SystemTAP
444 use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
446 # We always want to attempt to build with PIE support as it results
447 # in a more secure binary. But it doesn't work with static or if
448 # the current GCC doesn't have PIE support.
449 if use ${static_flag}; then
450 conf_opts+=( --static --disable-pie )
452 gcc-specs-pie && conf_opts+=( --enable-pie )
455 echo "../configure ${conf_opts[*]}"
457 ../configure "${conf_opts[@]}" || die "configure failed"
459 # FreeBSD's kernel does not support QEMU assigning/grabbing
460 # host USB devices yet
461 use kernel_FreeBSD && \
462 sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
470 softmmu_targets= softmmu_bins=()
471 user_targets= user_bins=()
473 for target in ${IUSE_SOFTMMU_TARGETS} ; do
474 if use "qemu_softmmu_targets_${target}"; then
475 softmmu_targets+=",${target}-softmmu"
476 softmmu_bins+=( "qemu-system-${target}" )
480 for target in ${IUSE_USER_TARGETS} ; do
481 if use "qemu_user_targets_${target}"; then
482 user_targets+=",${target}-linux-user"
483 user_bins+=( "qemu-${target}" )
487 softmmu_targets=${softmmu_targets#,}
488 user_targets=${user_targets#,}
490 [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
491 [[ -n ${user_targets} ]] && qemu_src_configure "user"
492 [[ -z ${softmmu_targets}${user_targets} ]] && qemu_src_configure "tools"
496 if [[ -n ${user_targets} ]]; then
501 if [[ -n ${softmmu_targets} ]]; then
502 cd "${S}/softmmu-build"
506 if [[ -z ${softmmu_targets}${user_targets} ]]; then
507 cd "${S}/tools-build"
513 if [[ -n ${softmmu_targets} ]]; then
514 cd "${S}/softmmu-build"
515 pax-mark m */qemu-system-* #515550
517 emake -j1 check-report.html
521 qemu_python_install() {
522 python_domodule "${S}/scripts/qmp/qmp.py"
524 python_doscript "${S}/scripts/kvm/kvm_stat"
525 python_doscript "${S}/scripts/kvm/vmxcap"
526 python_doscript "${S}/scripts/qmp/qmp-shell"
527 python_doscript "${S}/scripts/qmp/qemu-ga-client"
531 if [[ -n ${user_targets} ]]; then
533 emake DESTDIR="${ED}" install
535 # Install binfmt handler init script for user targets
536 newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
539 if [[ -n ${softmmu_targets} ]]; then
540 cd "${S}/softmmu-build"
541 emake DESTDIR="${ED}" install
543 # This might not exist if the test failed. #512010
544 [[ -e check-report.html ]] && dohtml check-report.html
546 if use kernel_linux; then
547 udev_dorules "${FILESDIR}"/65-kvm.rules
551 python_foreach_impl qemu_python_install
555 if [[ -z ${softmmu_targets}${user_targets} ]]; then
556 cd "${S}/tools-build"
557 emake DESTDIR="${ED}" install
560 # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
561 pushd "${ED}"/usr/bin >/dev/null
562 pax-mark m "${softmmu_bins[@]}" "${user_bins[@]}"
565 # Install config file example for qemu-bridge-helper
567 doins "${FILESDIR}/bridge.conf"
569 # Remove the docdir placed qmp-commands.txt
570 mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/qmp/"
573 dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
574 newdoc pc-bios/README README.pc-bios
577 if [[ -n ${softmmu_targets} ]]; then
578 # Remove SeaBIOS since we're using the SeaBIOS packaged one
579 rm "${ED}/usr/share/qemu/bios.bin"
580 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
581 dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
584 # Remove vgabios since we're using the vgabios packaged one
585 rm "${ED}/usr/share/qemu/vgabios.bin"
586 rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
587 rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
588 rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
589 rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
590 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
591 dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
592 dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
593 dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
594 dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
595 dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
598 # Remove sgabios since we're using the sgabios packaged one
599 rm "${ED}/usr/share/qemu/sgabios.bin"
600 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
601 dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
604 # Remove iPXE since we're using the iPXE packaged one
605 rm "${ED}"/usr/share/qemu/pxe-*.rom
606 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
607 dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
608 dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
609 dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
610 dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
611 dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
612 dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
616 qemu_support_kvm && readme.gentoo_create_doc
620 if qemu_support_kvm; then
621 readme.gentoo_print_elog
624 if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
628 fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
633 echo " $(best_version app-emulation/spice-protocol)"
634 echo " $(best_version sys-firmware/ipxe)"
635 echo " $(best_version sys-firmware/seabios)"
636 if has_version 'sys-firmware/seabios[binary]'; then
641 echo " $(best_version sys-firmware/vgabios)"