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 gnutls 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 usb usbredir +uuid vde +vhost-net \
37 virgl 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 tilegx"
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.
69 # Older versions of gnutls are supported, but it's simpler to just require
70 # the latest versions. This is also why we require nettle.
71 COMMON_LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
72 sys-libs/zlib[static-libs(+)]
73 xattr? ( sys-apps/attr[static-libs(+)] )"
74 SOFTMMU_LIB_DEPEND="${COMMON_LIB_DEPEND}
75 >=x11-libs/pixman-0.28.0[static-libs(+)]
76 accessibility? ( app-accessibility/brltty[static-libs(+)] )
77 aio? ( dev-libs/libaio[static-libs(+)] )
78 alsa? ( >=media-libs/alsa-lib-1.0.13 )
79 bluetooth? ( net-wireless/bluez )
80 caps? ( sys-libs/libcap-ng[static-libs(+)] )
81 curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
82 fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
83 glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
85 dev-libs/nettle[static-libs(+)]
86 >=net-libs/gnutls-3.0[static-libs(+)]
91 vte? ( x11-libs/vte:0 )
95 vte? ( x11-libs/vte:2.90 )
98 infiniband? ( sys-infiniband/librdmacm:=[static-libs(+)] )
99 iscsi? ( net-libs/libiscsi )
100 jpeg? ( virtual/jpeg:=[static-libs(+)] )
101 lzo? ( dev-libs/lzo:2[static-libs(+)] )
102 ncurses? ( sys-libs/ncurses:0=[static-libs(+)] )
103 nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
104 numa? ( sys-process/numactl[static-libs(+)] )
107 media-libs/libepoxy[static-libs(+)]
108 media-libs/mesa[static-libs(+)]
109 media-libs/mesa[egl,gles2]
111 png? ( media-libs/libpng:0=[static-libs(+)] )
112 pulseaudio? ( media-sound/pulseaudio )
113 rbd? ( sys-cluster/ceph[static-libs(+)] )
114 sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
118 >=media-libs/libsdl-1.2.11[static-libs(+)]
121 media-libs/libsdl2[X]
122 media-libs/libsdl2[static-libs(+)]
125 seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
126 smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
127 snappy? ( app-arch/snappy[static-libs(+)] )
129 >=app-emulation/spice-protocol-0.12.3
130 >=app-emulation/spice-0.12.0[static-libs(+)]
132 ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
133 usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
134 usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
135 uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
136 vde? ( net-misc/vde[static-libs(+)] )
137 virgl? ( media-libs/virglrenderer[static-libs(+)] )
138 virtfs? ( sys-libs/libcap )
139 xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
140 USER_LIB_DEPEND="${COMMON_LIB_DEPEND}"
141 X86_FIRMWARE_DEPEND="
142 >=sys-firmware/ipxe-1.0.0_p20130624
143 pin-upstream-blobs? (
144 ~sys-firmware/seabios-1.8.2
145 ~sys-firmware/sgabios-0.1_pre8
146 ~sys-firmware/vgabios-0.7a
148 !pin-upstream-blobs? (
154 !static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND//\[static-libs(+)]} ) " ${use_softmmu_targets}) )
155 !static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND//\[static-libs(+)]} ) " ${use_user_targets}) )
156 qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
157 qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
158 python? ( ${PYTHON_DEPS} )
159 systemtap? ( dev-util/systemtap )
160 xen? ( app-emulation/xen-tools:= )"
166 kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
167 gtk? ( nls? ( sys-devel/gettext ) )
168 static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND} ) " ${use_softmmu_targets}) )
169 static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND} ) " ${use_user_targets}) )
175 selinux? ( sec-policy/selinux-qemu )
178 STRIP_MASK="/usr/share/qemu/palcode-clipper"
181 usr/share/qemu/openbios-ppc
182 usr/share/qemu/openbios-sparc64
183 usr/share/qemu/openbios-sparc32
184 usr/share/qemu/palcode-clipper
185 usr/share/qemu/s390-ccw.img
186 usr/share/qemu/u-boot.e500
189 QA_WX_LOAD="usr/bin/qemu-i386
195 usr/bin/qemu-microblaze
196 usr/bin/qemu-microblazeel
202 usr/bin/qemu-ppc64abi32
208 usr/bin/qemu-sparc32plus
210 usr/bin/qemu-unicore32"
212 DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure
213 you have the kernel module loaded before running kvm. The easiest way to
214 ensure that the kernel module is loaded is to load it on boot.\n
215 For AMD CPUs the module is called 'kvm-amd'\n
216 For Intel CPUs the module is called 'kvm-intel'\n
217 Please review /etc/conf.d/modules for how to load these\n\n
218 Make sure your user is in the 'kvm' group\n
219 Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."
222 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
223 use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
224 use qemu_softmmu_targets_s390x; then
232 if use kernel_linux && kernel_is lt 2 6 25; then
233 eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
234 elif use kernel_linux; then
235 if ! linux_config_exists; then
236 eerror "Unable to check your kernel for KVM support"
238 CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
239 ERROR_KVM="You must enable KVM in your kernel to continue"
240 ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
241 ERROR_KVM_AMD+=" your kernel configuration."
242 ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
243 ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
244 ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
245 ERROR_TUN+=" into your kernel or loaded as a module to use the"
246 ERROR_TUN+=" virtual network device if using -net tap."
247 ERROR_BRIDGE="You will also need support for 802.1d"
248 ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
249 use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
250 ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
251 ERROR_VHOST_NET+=" support"
253 if use amd64 || use x86 || use amd64-linux || use x86-linux; then
254 CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
257 use python && CONFIG_CHECK+=" ~DEBUG_FS"
258 ERROR_DEBUG_FS="debugFS support required for kvm_stat"
260 # Now do the actual checks setup above
265 if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
266 eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
267 eerror "instances are still pointing to it. Please update your"
268 eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
269 eerror "and the right system binary (e.g. qemu-system-x86_64)."
270 die "update your virt configs to not use qemu-kvm"
278 # Sanity check to make sure target lists are kept up-to-date.
281 local detected sorted
283 pushd "${S}"/default-configs >/dev/null || die
285 # Force C locale until glibc is updated. #564936
286 detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
287 sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
288 if [[ ${sorted} != "${detected}" ]] ; then
289 eerror "The ebuild needs to be kept in sync."
290 eerror "${var}: ${sorted}"
291 eerror "$(printf '%-*s' ${#var} configure): ${detected}"
292 die "sync ${var} to the list of targets"
299 check_targets IUSE_SOFTMMU_TARGETS softmmu
300 check_targets IUSE_USER_TARGETS linux-user
302 # Alter target makefiles to accept CFLAGS set via flag-o
304 -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
305 Makefile Makefile.target || die
307 # Cheap hack to disable gettext .mo generation.
308 use nls || rm -f po/*.po
310 epatch "${FILESDIR}"/qemu-2.5.0-cflags.patch
311 [[ -n ${BACKPORTS} ]] && \
312 EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
315 # Fix ld and objcopy being called directly
316 tc-export AR LD OBJCOPY
325 # configures qemu based on the build directory and the build type
328 qemu_src_configure() {
329 debug-print-function ${FUNCNAME} "$@"
332 local builddir="${S}/${buildtype}-build"
333 local static_flag="static-${buildtype}"
340 --libdir=/usr/$(get_libdir)
341 --docdir=/usr/share/doc/${PF}/html
343 --disable-guest-agent
346 # We support gnutls/nettle for crypto operations. It is possible
347 # to use gcrypt when gnutls/nettle are disabled (but not when they
348 # are enabled), but it's not really worth the hassle. Disable it
349 # all the time to avoid automatically detecting it. #568856
354 --host-cc="$(tc-getBUILD_CC)"
355 $(use_enable debug debug-info)
356 $(use_enable debug debug-tcg)
358 $(use_enable tci tcg-interpreter)
359 $(use_enable xattr attr)
362 # Disable options not used by user targets as the default configure
363 # options will autoprobe and try to link in a bunch of unused junk.
365 if [[ ${buildtype} == "user" ]] ; then
366 echo "--disable-${2:-$1}"
372 $(conf_softmmu accessibility brlapi)
373 $(conf_softmmu aio linux-aio)
374 $(conf_softmmu bluetooth bluez)
375 $(conf_softmmu caps cap-ng)
378 $(conf_softmmu glusterfs)
379 $(conf_softmmu gnutls)
380 $(conf_softmmu gnutls nettle)
382 $(conf_softmmu infiniband rdma)
383 $(conf_softmmu iscsi libiscsi)
384 $(conf_softmmu jpeg vnc-jpeg)
385 $(conf_softmmu kernel_linux kvm)
387 $(conf_softmmu ncurses curses)
388 $(conf_softmmu nfs libnfs)
390 $(conf_softmmu opengl)
391 $(conf_softmmu png vnc-png)
393 $(conf_softmmu sasl vnc-sasl)
395 $(conf_softmmu seccomp)
396 $(conf_softmmu smartcard)
397 $(conf_softmmu snappy)
398 $(conf_softmmu spice)
399 $(conf_softmmu ssh libssh2)
400 $(conf_softmmu usb libusb)
401 $(conf_softmmu usbredir usb-redir)
404 $(conf_softmmu vhost-net)
405 $(conf_softmmu virgl virglrenderer)
406 $(conf_softmmu virtfs)
410 $(conf_softmmu xen xen-pci-passthrough)
411 $(conf_softmmu xfs xfsctl)
425 local audio_opts="oss"
426 use alsa && audio_opts="alsa,${audio_opts}"
427 use sdl && audio_opts="sdl,${audio_opts}"
428 use pulseaudio && audio_opts="pa,${audio_opts}"
434 --audio-drv-list="${audio_opts}"
436 use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
437 use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
449 local targets="${buildtype}_targets"
450 [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
452 # Add support for SystemTAP
453 use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
455 # We always want to attempt to build with PIE support as it results
456 # in a more secure binary. But it doesn't work with static or if
457 # the current GCC doesn't have PIE support.
458 if use ${static_flag}; then
459 conf_opts+=( --static --disable-pie )
461 gcc-specs-pie && conf_opts+=( --enable-pie )
464 echo "../configure ${conf_opts[*]}"
466 ../configure "${conf_opts[@]}" || die "configure failed"
468 # FreeBSD's kernel does not support QEMU assigning/grabbing
469 # host USB devices yet
470 use kernel_FreeBSD && \
471 sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
479 softmmu_targets= softmmu_bins=()
480 user_targets= user_bins=()
482 for target in ${IUSE_SOFTMMU_TARGETS} ; do
483 if use "qemu_softmmu_targets_${target}"; then
484 softmmu_targets+=",${target}-softmmu"
485 softmmu_bins+=( "qemu-system-${target}" )
489 for target in ${IUSE_USER_TARGETS} ; do
490 if use "qemu_user_targets_${target}"; then
491 user_targets+=",${target}-linux-user"
492 user_bins+=( "qemu-${target}" )
496 softmmu_targets=${softmmu_targets#,}
497 user_targets=${user_targets#,}
499 [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
500 [[ -n ${user_targets} ]] && qemu_src_configure "user"
501 [[ -z ${softmmu_targets}${user_targets} ]] && qemu_src_configure "tools"
505 if [[ -n ${user_targets} ]]; then
510 if [[ -n ${softmmu_targets} ]]; then
511 cd "${S}/softmmu-build"
515 if [[ -z ${softmmu_targets}${user_targets} ]]; then
516 cd "${S}/tools-build"
522 if [[ -n ${softmmu_targets} ]]; then
523 cd "${S}/softmmu-build"
524 pax-mark m */qemu-system-* #515550
526 emake -j1 check-report.html
530 qemu_python_install() {
531 python_domodule "${S}/scripts/qmp/qmp.py"
533 python_doscript "${S}/scripts/kvm/kvm_stat"
534 python_doscript "${S}/scripts/kvm/vmxcap"
535 python_doscript "${S}/scripts/qmp/qmp-shell"
536 python_doscript "${S}/scripts/qmp/qemu-ga-client"
540 if [[ -n ${user_targets} ]]; then
542 emake DESTDIR="${ED}" install
544 # Install binfmt handler init script for user targets
545 newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
548 if [[ -n ${softmmu_targets} ]]; then
549 cd "${S}/softmmu-build"
550 emake DESTDIR="${ED}" install
552 # This might not exist if the test failed. #512010
553 [[ -e check-report.html ]] && dohtml check-report.html
555 if use kernel_linux; then
556 udev_dorules "${FILESDIR}"/65-kvm.rules
560 python_foreach_impl qemu_python_install
564 if [[ -z ${softmmu_targets}${user_targets} ]]; then
565 cd "${S}/tools-build"
566 emake DESTDIR="${ED}" install
569 # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
570 pushd "${ED}"/usr/bin >/dev/null
571 pax-mark m "${softmmu_bins[@]}" "${user_bins[@]}"
574 # Install config file example for qemu-bridge-helper
576 doins "${FILESDIR}/bridge.conf"
578 # Remove the docdir placed qmp-commands.txt
579 mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/" || die
582 dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
583 newdoc pc-bios/README README.pc-bios
586 if [[ -n ${softmmu_targets} ]]; then
587 # Remove SeaBIOS since we're using the SeaBIOS packaged one
588 rm "${ED}/usr/share/qemu/bios.bin"
589 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
590 dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
593 # Remove vgabios since we're using the vgabios packaged one
594 rm "${ED}/usr/share/qemu/vgabios.bin"
595 rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
596 rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
597 rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
598 rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
599 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
600 dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
601 dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
602 dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
603 dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
604 dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
607 # Remove sgabios since we're using the sgabios packaged one
608 rm "${ED}/usr/share/qemu/sgabios.bin"
609 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
610 dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
613 # Remove iPXE since we're using the iPXE packaged one
614 rm "${ED}"/usr/share/qemu/pxe-*.rom
615 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
616 dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
617 dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
618 dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
619 dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
620 dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
621 dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
625 qemu_support_kvm && readme.gentoo_create_doc
629 if qemu_support_kvm; then
630 readme.gentoo_print_elog
633 if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
637 fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
642 echo " $(best_version app-emulation/spice-protocol)"
643 echo " $(best_version sys-firmware/ipxe)"
644 echo " $(best_version sys-firmware/seabios)"
645 if has_version 'sys-firmware/seabios[binary]'; then
650 echo " $(best_version sys-firmware/vgabios)"