]> git.draconx.ca Git - gentoo-draconx.git/blob - app-emulation/qemu/qemu-1.2.2-r3.ebuild
Merge branch 'amythaon'
[gentoo-draconx.git] / app-emulation / qemu / qemu-1.2.2-r3.ebuild
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 $
4
5 EAPI=5
6
7
8 PYTHON_DEPEND="2:2.4"
9 inherit eutils flag-o-matic linux-info toolchain-funcs multilib python user udev
10
11 SRC_URI="http://wiki.qemu.org/download/${P}.tar.bz2"
12 KEYWORDS="~amd64 ~ppc ~ppc64 ~x86 ~x86-fbsd"
13
14 DESCRIPTION="Free machine emulator and virtualizer"
15 HOMEPAGE="http://www.qemu.org/"
16
17 LICENSE="GPL-2 LGPL-2 BSD-2"
18 SLOT="0"
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 \
23 xen xfs"
24
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"
29
30 # Setup the default SoftMMU targets, while using the loops
31 # below to setup the other targets.
32 REQUIRED_USE="|| ("
33
34 for target in ${IUSE_SOFTMMU_TARGETS}; do
35         IUSE="${IUSE} qemu_softmmu_targets_${target}"
36         REQUIRED_USE="${REQUIRED_USE} qemu_softmmu_targets_${target}"
37 done
38 REQUIRED_USE="${REQUIRED_USE} )"
39
40 for target in ${IUSE_USER_TARGETS}; do
41         IUSE="${IUSE} qemu_user_targets_${target}"
42 done
43
44 # Block USE flag configurations known to not work
45 REQUIRED_USE="${REQUIRED_USE}
46         kvm? ( kernel_linux )
47         static? ( static-softmmu static-user )
48         static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl )
49         virtfs? ( xattr )"
50
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(+)]} )
73         !app-emulation/kqemu
74         qemu_softmmu_targets_i386? (
75                 sys-firmware/ipxe
76                 ~sys-firmware/seabios-1.7.1
77                 ~sys-firmware/sgabios-0.1_pre8
78                 ~sys-firmware/vgabios-0.7a
79         )
80         qemu_softmmu_targets_x86_64? (
81                 sys-firmware/ipxe
82                 ~sys-firmware/seabios-1.7.1
83                 ~sys-firmware/sgabios-0.1_pre8
84                 ~sys-firmware/vgabios-0.7a
85         )
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 )"
100
101 DEPEND="${RDEPEND}
102         virtual/pkgconfig
103         doc? ( app-text/texi2html )
104         kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
105         static-softmmu? ( ${LIB_DEPEND} )"
106
107 STRIP_MASK="/usr/share/qemu/palcode-clipper"
108
109 QA_PREBUILT="
110         usr/share/qemu/openbios-ppc
111         usr/share/qemu/openbios-sparc64
112         usr/share/qemu/openbios-sparc32
113         usr/share/qemu/palcode-clipper"
114
115 QA_WX_LOAD="usr/bin/qemu-i386
116         usr/bin/qemu-x86_64
117         usr/bin/qemu-alpha
118         usr/bin/qemu-arm
119         usr/bin/qemu-cris
120         usr/bin/qemu-m68k
121         usr/bin/qemu-microblaze
122         usr/bin/qemu-microblazeel
123         usr/bin/qemu-mips
124         usr/bin/qemu-mipsel
125         usr/bin/qemu-or32
126         usr/bin/qemu-ppc
127         usr/bin/qemu-ppc64
128         usr/bin/qemu-ppc64abi32
129         usr/bin/qemu-sh4
130         usr/bin/qemu-sh4eb
131         usr/bin/qemu-sparc
132         usr/bin/qemu-sparc64
133         usr/bin/qemu-armeb
134         usr/bin/qemu-sparc32plus
135         usr/bin/qemu-s390x
136         usr/bin/qemu-unicore32"
137
138 qemu_support_kvm() {
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
142                 return 0
143         fi
144
145         return 1
146 }
147
148 pkg_setup() {
149         python_set_active_version 2
150         python_pkg_setup
151
152         enewgroup kvm 78
153 }
154
155 src_prepare() {
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
159
160         python_convert_shebangs -r 2 "${S}/scripts/kvm/kvm_stat"
161         python_convert_shebangs -r 2 "${S}/scripts/kvm/vmxcap"
162
163         epatch "${FILESDIR}"/qemu-1.2.0-cflags.patch
164         [[ -n ${BACKPORTS} ]] && \
165                 EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
166                         epatch
167
168         # Fix ld and objcopy being called directly
169         tc-export LD OBJCOPY
170
171         # Verbose builds
172         MAKEOPTS+=" V=1"
173
174         epatch_user
175 }
176
177 ##
178 # configures qemu based on the build directory and the build type
179 # we are using.
180 #
181 qemu_src_configure() {
182         debug-print-function $FUNCNAME "$@"
183
184         local buildtype=$1
185         local builddir=$2
186         local conf_opts audio_opts
187         local static_flag="static-${buildtype}"
188
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"
198
199         # audio options
200         audio_opts="oss"
201         use alsa && audio_opts="alsa,${audio_opts}"
202         use sdl && audio_opts="sdl,${audio_opts}"
203         use pulseaudio && audio_opts="pa,${audio_opts}"
204
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"
211         fi
212
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}"
249         fi
250
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)"
255
256         # Add support for SystemTAP
257         use systemtap && conf_opts="${conf_opts} --enable-trace-backend=dtrace"
258
259         # Add support for static builds
260         use ${static_flag} && conf_opts="${conf_opts} --static --disable-pie"
261
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"
267         fi
268
269         einfo "./configure ${conf_opts}"
270         cd ${builddir}
271         ../configure \
272                 --cc="$(tc-getCC)" \
273                 --host-cc="$(tc-getBUILD_CC)" \
274                 ${conf_opts} \
275                 || die "configure failed"
276
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
281 }
282
283 src_configure() {
284         softmmu_targets=
285         user_targets=
286
287         for target in ${IUSE_SOFTMMU_TARGETS} ; do
288                 use "qemu_softmmu_targets_${target}" && \
289                 softmmu_targets="${softmmu_targets},${target}-softmmu"
290         done
291
292         for target in ${IUSE_USER_TARGETS} ; do
293                 use "qemu_user_targets_${target}" && \
294                 user_targets="${user_targets},${target}-linux-user"
295         done
296
297         [[ -n ${softmmu_targets} ]] && \
298                 einfo "Building the following softmmu targets: ${softmmu_targets}"
299
300         [[ -n ${user_targets} ]] && \
301                 einfo "Building the following user targets: ${user_targets}"
302
303         if [[ -n ${softmmu_targets} ]]; then
304                 mkdir "${S}/softmmu-build"
305                 qemu_src_configure "softmmu" "${S}/softmmu-build"
306         fi
307
308         if [[ -n ${user_targets} ]]; then
309                 mkdir "${S}/user-build"
310                 qemu_src_configure "user" "${S}/user-build"
311         fi
312 }
313
314 src_compile() {
315         if [[ -n ${user_targets} ]]; then
316                 cd "${S}/user-build"
317                 default
318         fi
319
320         if [[ -n ${softmmu_targets} ]]; then
321                 cd "${S}/softmmu-build"
322                 default
323         fi
324 }
325
326 src_install() {
327         if [[ -n ${user_targets} ]]; then
328                 cd "${S}/user-build"
329                 emake DESTDIR="${ED}" install
330
331                 # Install binfmt handler init script for user targets
332                 newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
333         fi
334
335         if [[ -n ${softmmu_targets} ]]; then
336                 cd "${S}/softmmu-build"
337                 emake DESTDIR="${ED}" install
338
339                 if use kernel_linux; then
340                         udev_dorules "${FILESDIR}"/65-kvm.rules
341                 fi
342
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."
351                 fi
352
353                 use python && dobin "${S}/scripts/kvm/kvm_stat"
354                 use python && dobin "${S}/scripts/kvm/vmxcap"
355         fi
356
357         cd "${S}"
358         dodoc Changelog MAINTAINERS TODO pci-ids.txt
359         newdoc pc-bios/README README.pc-bios
360
361         # Avoid collision with app-emulation/libcacard
362         use smartcard && mv "${ED}/usr/bin/vscclient" "${ED}/usr/bin/qemu-vscclient"
363
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
368         fi
369
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
382         fi
383
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
388         fi
389
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
399         fi
400 }
401
402 pkg_postinst() {
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"
410                 elog
411                 elog "Make sure your user is in the 'kvm' group"
412                 elog "Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."
413                 elog
414         fi
415 }