1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/app-emulation/qemu/qemu-1.2.2-r3.ebuild,v 1.2 2013/02/10 21:50:04 cardoe Exp $
9 inherit eutils flag-o-matic linux-info toolchain-funcs multilib python user udev
11 SRC_URI="http://wiki.qemu.org/download/${P}.tar.bz2"
12 KEYWORDS="~amd64 ~ppc ~ppc64 ~x86 ~x86-fbsd"
14 DESCRIPTION="Free machine emulator and virtualizer"
15 HOMEPAGE="http://www.qemu.org/"
17 LICENSE="GPL-2 LGPL-2 BSD-2"
19 IUSE="+aio alsa bluetooth brltty +caps +curl debug doc fdt +jpeg kernel_linux \
20 kernel_FreeBSD kvm mixemu ncurses opengl +png pulseaudio python rbd sasl \
21 +seccomp sdl selinux smartcard spice static static-softmmu static-user \
22 systemtap tci +threads tls usbredir +uuid vde +vhost-net virtfs +vnc xattr \
25 COMMON_TARGETS="i386 x86_64 alpha arm cris m68k microblaze microblazeel mips
26 mipsel or32 ppc ppc64 sh4 sh4eb sparc sparc64 s390x unicore32"
27 IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS} lm32 mips64 mips64el ppcemb xtensa xtensaeb"
28 IUSE_USER_TARGETS="${COMMON_TARGETS} armeb ppc64abi32 sparc32plus"
30 # Setup the default SoftMMU targets, while using the loops
31 # below to setup the other targets.
34 for target in ${IUSE_SOFTMMU_TARGETS}; do
35 IUSE="${IUSE} qemu_softmmu_targets_${target}"
36 REQUIRED_USE="${REQUIRED_USE} qemu_softmmu_targets_${target}"
38 REQUIRED_USE="${REQUIRED_USE} )"
40 for target in ${IUSE_USER_TARGETS}; do
41 IUSE="${IUSE} qemu_user_targets_${target}"
44 # Block USE flag configurations known to not work
45 REQUIRED_USE="${REQUIRED_USE}
47 static? ( static-softmmu static-user )
48 static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl )
51 # Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
52 LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
53 sys-apps/pciutils[static-libs(+)]
54 sys-libs/zlib[static-libs(+)]
55 aio? ( dev-libs/libaio[static-libs(+)] )
56 caps? ( sys-libs/libcap-ng[static-libs(+)] )
57 curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
58 fdt? ( >=sys-apps/dtc-1.2.0[static-libs(+)] )
59 jpeg? ( virtual/jpeg[static-libs(+)] )
60 ncurses? ( sys-libs/ncurses[static-libs(+)] )
61 png? ( media-libs/libpng[static-libs(+)] )
62 rbd? ( sys-cluster/ceph[static-libs(+)] )
63 sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
64 sdl? ( >=media-libs/libsdl-1.2.11[static-libs(+)] )
65 seccomp? ( >=sys-libs/libseccomp-1.0.1[static-libs(+)] )
66 spice? ( >=app-emulation/spice-0.9.0[static-libs(+)] )
67 tls? ( net-libs/gnutls[static-libs(+)] )
68 uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
69 vde? ( net-misc/vde[static-libs(+)] )
70 xattr? ( sys-apps/attr[static-libs(+)] )
71 xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
72 RDEPEND="!static-softmmu? ( ${LIB_DEPEND//\[static-libs(+)]} )
74 qemu_softmmu_targets_i386? (
76 ~sys-firmware/seabios-1.7.1
77 ~sys-firmware/sgabios-0.1_pre8
78 ~sys-firmware/vgabios-0.7a
80 qemu_softmmu_targets_x86_64? (
82 ~sys-firmware/seabios-1.7.1
83 ~sys-firmware/sgabios-0.1_pre8
84 ~sys-firmware/vgabios-0.7a
86 alsa? ( >=media-libs/alsa-lib-1.0.13 )
87 bluetooth? ( net-wireless/bluez )
88 brltty? ( app-accessibility/brltty )
89 opengl? ( virtual/opengl )
90 pulseaudio? ( media-sound/pulseaudio )
91 python? ( =dev-lang/python-2*[ncurses] )
92 sdl? ( media-libs/libsdl[X] )
93 selinux? ( sec-policy/selinux-qemu )
94 smartcard? ( dev-libs/nss )
95 spice? ( >=app-emulation/spice-protocol-0.12.2 )
96 systemtap? ( dev-util/systemtap )
97 usbredir? ( ~sys-apps/usbredir-0.4.4 )
98 virtfs? ( sys-libs/libcap )
99 xen? ( app-emulation/xen-tools )"
103 doc? ( app-text/texi2html )
104 kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
105 static-softmmu? ( ${LIB_DEPEND} )"
107 STRIP_MASK="/usr/share/qemu/palcode-clipper"
110 usr/share/qemu/openbios-ppc
111 usr/share/qemu/openbios-sparc64
112 usr/share/qemu/openbios-sparc32
113 usr/share/qemu/palcode-clipper"
115 QA_WX_LOAD="usr/bin/qemu-i386
121 usr/bin/qemu-microblaze
122 usr/bin/qemu-microblazeel
128 usr/bin/qemu-ppc64abi32
134 usr/bin/qemu-sparc32plus
136 usr/bin/qemu-unicore32"
139 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
140 use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
141 use qemu_softmmu_targets_s390x; then
149 python_set_active_version 2
156 # Alter target makefiles to accept CFLAGS set via flag-o
157 sed -i 's/^\(C\|OP_C\|HELPER_C\)FLAGS=/\1FLAGS+=/' \
158 Makefile Makefile.target || die
160 python_convert_shebangs -r 2 "${S}/scripts/kvm/kvm_stat"
161 python_convert_shebangs -r 2 "${S}/scripts/kvm/vmxcap"
163 epatch "${FILESDIR}"/qemu-1.2.0-cflags.patch
164 [[ -n ${BACKPORTS} ]] && \
165 EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
168 # Fix ld and objcopy being called directly
178 # configures qemu based on the build directory and the build type
181 qemu_src_configure() {
182 debug-print-function $FUNCNAME "$@"
186 local conf_opts audio_opts
187 local static_flag="static-${buildtype}"
189 conf_opts="--prefix=/usr"
190 conf_opts+=" --sysconfdir=/etc"
191 conf_opts+=" --docdir=/usr/share/doc/${PF}/html"
192 conf_opts+=" --disable-bsd-user"
193 conf_opts+=" --disable-guest-agent"
194 conf_opts+=" --disable-libiscsi"
195 conf_opts+=" --disable-strip"
196 conf_opts+=" --disable-werror"
197 conf_opts+=" --python=python2"
201 use alsa && audio_opts="alsa,${audio_opts}"
202 use sdl && audio_opts="sdl,${audio_opts}"
203 use pulseaudio && audio_opts="pa,${audio_opts}"
205 if [[ ${buildtype} == "user" ]]; then
206 conf_opts+=" --enable-linux-user"
207 conf_opts+=" --disable-system"
208 conf_opts+=" --target-list=${user_targets}"
209 conf_opts+=" --disable-bluez"
210 conf_opts+=" --disable-sdl"
213 if [[ ${buildtype} == "softmmu" ]]; then
214 conf_opts+=" --disable-linux-user"
215 conf_opts+=" --enable-system"
216 conf_opts+=" --target-list=${softmmu_targets}"
217 conf_opts+=" $(use_enable bluetooth bluez)"
218 conf_opts+=" $(use_enable sdl)"
219 conf_opts+=" $(use_enable aio linux-aio)"
220 conf_opts+=" $(use_enable brltty brlapi)"
221 conf_opts+=" $(use_enable caps cap-ng)"
222 conf_opts+=" $(use_enable curl)"
223 conf_opts+=" $(use_enable fdt)"
224 conf_opts+=" $(use_enable jpeg vnc-jpeg)"
225 conf_opts+=" $(use_enable kvm)"
226 conf_opts+=" $(use_enable kernel_linux nptl)"
227 conf_opts+=" $(use_enable ncurses curses)"
228 conf_opts+=" $(use_enable opengl)"
229 conf_opts+=" $(use_enable png vnc-png)"
230 conf_opts+=" $(use_enable rbd)"
231 conf_opts+=" $(use_enable sasl vnc-sasl)"
232 conf_opts+=" $(use_enable seccomp)"
233 conf_opts+=" $(use_enable smartcard smartcard)"
234 conf_opts+=" $(use_enable smartcard smartcard-nss)"
235 conf_opts+=" $(use_enable spice)"
236 conf_opts+=" $(use_enable tls vnc-tls)"
237 conf_opts+=" $(use_enable usbredir usb-redir)"
238 conf_opts+=" $(use_enable uuid)"
239 conf_opts+=" $(use_enable vde)"
240 conf_opts+=" $(use_enable vhost-net)"
241 conf_opts+=" $(use_enable virtfs)"
242 conf_opts+=" $(use_enable vnc)"
243 conf_opts+=" $(use_enable xattr attr)"
244 conf_opts+=" $(use_enable xen)"
245 conf_opts+=" $(use_enable xen xen-pci-passthrough)"
246 conf_opts+=" $(use_enable xfs xfsctl)"
247 use mixemu && conf_opts+=" --enable-mixemu"
248 conf_opts+=" --audio-drv-list=${audio_opts}"
251 conf_opts+=" $(use_enable debug debug-info)"
252 conf_opts+=" $(use_enable debug debug-tcg)"
253 conf_opts+=" $(use_enable doc docs)"
254 conf_opts+=" $(use_enable tci tcg-interpreter)"
256 # Add support for SystemTAP
257 use systemtap && conf_opts="${conf_opts} --enable-trace-backend=dtrace"
259 # Add support for static builds
260 use ${static_flag} && conf_opts="${conf_opts} --static --disable-pie"
262 # We always want to attempt to build with PIE support as it results
263 # in a more secure binary. But it doesn't work with static or if
264 # the current GCC doesn't have PIE support.
265 if ! use ${static_flag} && gcc-specs-pie; then
266 conf_opts="${conf_opts} --enable-pie"
269 einfo "./configure ${conf_opts}"
273 --host-cc="$(tc-getBUILD_CC)" \
275 || die "configure failed"
277 # FreeBSD's kernel does not support QEMU assigning/grabbing
278 # host USB devices yet
279 use kernel_FreeBSD && \
280 sed -E -e "s|^(HOST_USB=)bsd|\1stub|" -i "${S}"/config-host.mak
287 for target in ${IUSE_SOFTMMU_TARGETS} ; do
288 use "qemu_softmmu_targets_${target}" && \
289 softmmu_targets="${softmmu_targets},${target}-softmmu"
292 for target in ${IUSE_USER_TARGETS} ; do
293 use "qemu_user_targets_${target}" && \
294 user_targets="${user_targets},${target}-linux-user"
297 [[ -n ${softmmu_targets} ]] && \
298 einfo "Building the following softmmu targets: ${softmmu_targets}"
300 [[ -n ${user_targets} ]] && \
301 einfo "Building the following user targets: ${user_targets}"
303 if [[ -n ${softmmu_targets} ]]; then
304 mkdir "${S}/softmmu-build"
305 qemu_src_configure "softmmu" "${S}/softmmu-build"
308 if [[ -n ${user_targets} ]]; then
309 mkdir "${S}/user-build"
310 qemu_src_configure "user" "${S}/user-build"
315 if [[ -n ${user_targets} ]]; then
320 if [[ -n ${softmmu_targets} ]]; then
321 cd "${S}/softmmu-build"
327 if [[ -n ${user_targets} ]]; then
329 emake DESTDIR="${ED}" install
331 # Install binfmt handler init script for user targets
332 newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
335 if [[ -n ${softmmu_targets} ]]; then
336 cd "${S}/softmmu-build"
337 emake DESTDIR="${ED}" install
339 if use kernel_linux; then
340 udev_dorules "${FILESDIR}"/65-kvm.rules
343 if use qemu_softmmu_targets_x86_64 ; then
344 dosym /usr/bin/qemu-system-x86_64 /usr/bin/qemu-kvm
345 ewarn "The deprecated '/usr/bin/kvm' symlink is no longer installed"
346 ewarn "You should use '/usr/bin/qemu-kvm', you may need to edit"
347 ewarn "your libvirt configs or other wrappers for ${PN}"
348 elif use x86 || use amd64; then
349 elog "You disabled QEMU_SOFTMMU_TARGETS=x86_64, this disables install"
350 elog "of the /usr/bin/qemu-kvm symlink."
353 use python && dobin "${S}/scripts/kvm/kvm_stat"
354 use python && dobin "${S}/scripts/kvm/vmxcap"
358 dodoc Changelog MAINTAINERS TODO pci-ids.txt
359 newdoc pc-bios/README README.pc-bios
361 # Avoid collision with app-emulation/libcacard
362 use smartcard && mv "${ED}/usr/bin/vscclient" "${ED}/usr/bin/qemu-vscclient"
364 # Remove SeaBIOS since we're using the SeaBIOS packaged one
365 rm "${ED}/usr/share/qemu/bios.bin"
366 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
367 dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
370 # Remove vgabios since we're using the vgabios packaged one
371 rm "${ED}/usr/share/qemu/vgabios.bin"
372 rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
373 rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
374 rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
375 rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
376 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
377 dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
378 dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
379 dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
380 dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
381 dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
384 # Remove sgabios since we're using the sgabios packaged one
385 rm "${ED}/usr/share/qemu/sgabios.bin"
386 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
387 dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
390 # Remove iPXE since we're using the iPXE packaged one
391 rm "${ED}"/usr/share/qemu/pxe-*.rom
392 if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
393 dosym ../ipxe/808610de.rom /usr/share/qemu/pxe-e1000.rom
394 dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
395 dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
396 dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
397 dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
398 dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
403 if qemu_support_kvm; then
404 elog "If you don't have kvm compiled into the kernel, make sure you have"
405 elog "the kernel module loaded before running kvm. The easiest way to"
406 elog "ensure that the kernel module is loaded is to load it on boot."
407 elog "For AMD CPUs the module is called 'kvm-amd'"
408 elog "For Intel CPUs the module is called 'kvm-intel'"
409 elog "Please review /etc/conf.d/modules for how to load these"
411 elog "Make sure your user is in the 'kvm' group"
412 elog "Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."