Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 544150
Collapse All | Expand All

(-)a/app-emulation/qemu/files/qemu-binfmt-helper (+123 lines)
Line 0 Link Here
1
#!/bin/sh
2
# Copyright 1999-2016 Gentoo Foundation
3
# Distributed under the terms of the GNU General Public License v2
4
# $Id$
5
6
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
7
8
# Defaulting to OC should be safe because it comes down to:
9
#  - do we trust the interp itself to not be malicious?  yes; we built it.
10
#  - do we trust the programs we're running?  ish; same permission as native
11
#	 binaries apply.  so if user can do bad stuff natively, cross isn't worse.
12
: ${QEMU_BINFMT_FLAGS:=OC}
13
14
start() {
15
	[ -f /proc/sys/fs/binfmt_misc/register ] || return
16
17
	# probe cpu type
18
	cpu=`uname -m`
19
	case "$cpu" in
20
		i386|i486|i586|i686|i86pc|BePC|x86_64)
21
			cpu="i386"
22
			;;
23
		m68k)
24
			cpu="m68k"
25
			;;
26
		mips*)
27
			cpu="mips"
28
		;;
29
		"Power Macintosh"|ppc|ppc64)
30
			cpu="ppc"
31
		;;
32
		armv[4-9]*)
33
			cpu="arm"
34
		;;
35
		sparc*)
36
			cpu="sparc"
37
		;;
38
	esac
39
40
	# register the interpreter for each cpu except for the native one
41
	if [ $cpu != "i386" -a -x "/usr/bin/qemu-i386" ] ; then
42
		echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-i386:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
43
		echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-i386:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
44
	fi
45
	if [ $cpu != "alpha" -a -x "/usr/bin/qemu-alpha" ] ; then
46
		echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-alpha:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
47
	fi
48
	if [ $cpu != "arm" -a -x "/usr/bin/qemu-arm" ] ; then
49
		echo	':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
50
	fi
51
	if [ $cpu != "arm" -a -x "/usr/bin/qemu-armeb" ] ; then
52
		echo	':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
53
	fi
54
	if [ $cpu != "aarch64" -a -x "/usr/bin/qemu-aarch64" ] ; then
55
		echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
56
	fi
57
	if [ $cpu != "sparc" -a -x "/usr/bin/qemu-sparc" ] ; then
58
		echo	':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sparc:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
59
	fi
60
	if [ $cpu != "ppc" -a -x "/usr/bin/qemu-ppc" ] ; then
61
		echo	':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-ppc:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
62
	fi
63
	if [ $cpu != "m68k" -a -x "/usr/bin/qemu-m68k" ] ; then
64
		#echo	'Please check cpu value and header information for m68k!'
65
		echo	':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-m68k:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
66
	fi
67
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips" ] ; then
68
		# FIXME: We could use the other endianness on a MIPS host.
69
		echo	':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
70
	fi
71
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsel" ] ; then
72
		echo	':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsel:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
73
	fi
74
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsn32" ] ; then
75
		echo	':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mipsn32:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
76
	fi
77
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsn32el" ] ; then
78
		echo	':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsn32el:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
79
	fi
80
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips64" ] ; then
81
		echo	':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips64:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
82
	fi
83
	if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips64el" ] ; then
84
		echo	':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mips64el:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
85
	fi
86
	if [ $cpu != "sh" -a -x "/usr/bin/qemu-sh4" ] ; then
87
		echo	 ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-sh4:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
88
	fi
89
	if [ $cpu != "sh" -a -x "/usr/bin/qemu-sh4eb" ] ; then
90
		echo	 ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sh4eb:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
91
	fi
92
	if [ $cpu != "s390x" -a -x "/usr/bin/qemu-s390x" ] ; then
93
		echo	':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-s390x:'"${QEMU_BINFMT_FLAGS}" > /proc/sys/fs/binfmt_misc/register
94
	fi
95
}
96
97
stop() {
98
	local arches
99
100
	arches="${arches} i386 i486"
101
	arches="${arches} alpha"
102
	arches="${arches} arm armeb"
103
	arches="${arches} aarch64"
104
	arches="${arches} sparc"
105
	arches="${arches} ppc"
106
	arches="${arches} m68k"
107
	arches="${arches} mips mipsel mipsn32 mipsn32el mips64 mips64el"
108
	arches="${arches} sh4 sh4eb"
109
	arches="${arches} s390x"
110
111
	for a in ${arches}; do
112
		if [ -f /proc/sys/fs/binfmt_misc/$a ] ; then
113
			echo '-1' > /proc/sys/fs/binfmt_misc/$a
114
		fi
115
	done
116
}
117
118
case "$1" in
119
	start|stop) "$1" ;;
120
	*) exit 1 ;;
121
esac
122
123
# vim: ts=4 :
(-)a/app-emulation/qemu/files/qemu-binfmt.initd-r2 (+46 lines)
Line 0 Link Here
1
#!/sbin/runscript
2
# Copyright 1999-2016 Gentoo Foundation
3
# Distributed under the terms of the GNU General Public License v2
4
# $Id$
5
6
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
7
8
# Defaulting to OC should be safe because it comes down to:
9
#  - do we trust the interp itself to not be malicious?  yes; we built it.
10
#  - do we trust the programs we're running?  ish; same permission as native
11
#	 binaries apply.  so if user can do bad stuff natively, cross isn't worse.
12
: ${QEMU_BINFMT_FLAGS:=OC}
13
14
depend() {
15
	 after procfs
16
}
17
18
start() {
19
	ebegin "Registering qemu-user binaries (flags: ${QEMU_BINFMT_FLAGS})"
20
21
	if [ ! -d /proc/sys/fs/binfmt_misc ] ; then
22
		modprobe -q binfmt_misc
23
	fi
24
25
	if [ ! -d /proc/sys/fs/binfmt_misc ] ; then
26
		 eend $? "You need support for 'misc binaries' in your kernel!" || return
27
	fi
28
29
	if [ ! -f /proc/sys/fs/binfmt_misc/register ] ; then
30
		mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc >/dev/null 2>&1
31
		eend $? || return
32
	fi
33
34
	export QEMU_BINFMT_FLAGS
35
	/usr/libexec/qemu-binfmt-helper start
36
37
	eend $?
38
}
39
40
stop() {
41
	ebegin "Unregistering qemu-user binaries"
42
	/usr/libexec/qemu-binfmt-helper stop
43
	eend $?
44
}
45
46
# vim: ts=4 :
(-)a/app-emulation/qemu/files/qemu-binfmt.service (+8 lines)
Line 0 Link Here
1
[Unit]
2
Description=Register qemu-user binaries
3
4
[Service]
5
Type=oneshot
6
RemainAfterExit=true
7
ExecStart=/usr/libexec/qemu-binfmt-helper start
8
ExecStop=/usr/libexec/qemu-binfmt-helper stop
(-)a/app-emulation/qemu/qemu-2.5.0-r4.ebuild (+699 lines)
Line 0 Link Here
1
# Copyright 1999-2016 Gentoo Foundation
2
# Distributed under the terms of the GNU General Public License v2
3
# $Id$
4
5
EAPI=5
6
7
PYTHON_COMPAT=( python2_7 )
8
PYTHON_REQ_USE="ncurses,readline"
9
10
PLOCALES="de_DE fr_FR hu it tr zh_CN"
11
12
inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
13
	user udev fcaps readme.gentoo pax-utils l10n systemd
14
15
BACKPORTS=
16
17
if [[ ${PV} = *9999* ]]; then
18
	EGIT_REPO_URI="git://git.qemu.org/qemu.git"
19
	inherit git-2
20
	SRC_URI=""
21
else
22
	SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2
23
	${BACKPORTS:+
24
		https://dev.gentoo.org/~cardoe/distfiles/${P}-${BACKPORTS}.tar.xz}"
25
	KEYWORDS="amd64 ~arm64 ~ppc ~ppc64 x86 ~x86-fbsd"
26
fi
27
28
DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
29
HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
30
31
LICENSE="GPL-2 LGPL-2 BSD-2"
32
SLOT="0"
33
IUSE="accessibility +aio alsa bluetooth +caps +curl debug +fdt glusterfs \
34
gnutls gtk gtk2 infiniband iscsi +jpeg \
35
kernel_linux kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs
36
+png pulseaudio python \
37
rbd sasl +seccomp sdl sdl2 selinux smartcard snappy spice ssh static static-softmmu
38
static-user systemtap tci test +threads usb usbredir +uuid vde +vhost-net \
39
virgl virtfs +vnc vte xattr xen xfs"
40
41
COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel mips
42
mips64 mips64el mipsel or32 ppc ppc64 s390x sh4 sh4eb sparc sparc64 unicore32
43
x86_64"
44
IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS} lm32 moxie ppcemb tricore xtensa xtensaeb"
45
IUSE_USER_TARGETS="${COMMON_TARGETS} armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus tilegx"
46
47
use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
48
use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
49
IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
50
51
# Allow no targets to be built so that people can get a tools-only build.
52
# Block USE flag configurations known to not work.
53
REQUIRED_USE="${PYTHON_REQUIRED_USE}
54
	gtk2? ( gtk )
55
	qemu_softmmu_targets_arm? ( fdt )
56
	qemu_softmmu_targets_microblaze? ( fdt )
57
	qemu_softmmu_targets_ppc? ( fdt )
58
	qemu_softmmu_targets_ppc64? ( fdt )
59
	sdl2? ( sdl )
60
	static? ( static-softmmu static-user )
61
	static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl !gtk !gtk2 )
62
	virtfs? ( xattr )
63
	vte? ( gtk )"
64
65
# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
66
#
67
# The attr lib isn't always linked in (although the USE flag is always
68
# respected).  This is because qemu supports using the C library's API
69
# when available rather than always using the extranl library.
70
#
71
# Older versions of gnutls are supported, but it's simpler to just require
72
# the latest versions.  This is also why we require nettle.
73
COMMON_LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
74
	sys-libs/zlib[static-libs(+)]
75
	xattr? ( sys-apps/attr[static-libs(+)] )"
76
SOFTMMU_LIB_DEPEND="${COMMON_LIB_DEPEND}
77
	>=x11-libs/pixman-0.28.0[static-libs(+)]
78
	accessibility? ( app-accessibility/brltty[static-libs(+)] )
79
	aio? ( dev-libs/libaio[static-libs(+)] )
80
	alsa? ( >=media-libs/alsa-lib-1.0.13 )
81
	bluetooth? ( net-wireless/bluez )
82
	caps? ( sys-libs/libcap-ng[static-libs(+)] )
83
	curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
84
	fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
85
	glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
86
	gnutls? (
87
		dev-libs/nettle[static-libs(+)]
88
		>=net-libs/gnutls-3.0[static-libs(+)]
89
	)
90
	gtk? (
91
		gtk2? (
92
			x11-libs/gtk+:2
93
			vte? ( x11-libs/vte:0 )
94
		)
95
		!gtk2? (
96
			x11-libs/gtk+:3
97
			vte? ( x11-libs/vte:2.90 )
98
		)
99
	)
100
	infiniband? ( sys-infiniband/librdmacm:=[static-libs(+)] )
101
	iscsi? ( net-libs/libiscsi )
102
	jpeg? ( virtual/jpeg:=[static-libs(+)] )
103
	lzo? ( dev-libs/lzo:2[static-libs(+)] )
104
	ncurses? ( sys-libs/ncurses:0=[static-libs(+)] )
105
	nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
106
	numa? ( sys-process/numactl[static-libs(+)] )
107
	opengl? (
108
		virtual/opengl
109
		media-libs/libepoxy[static-libs(+)]
110
		media-libs/mesa[static-libs(+)]
111
		media-libs/mesa[egl,gles2]
112
	)
113
	png? ( media-libs/libpng:0=[static-libs(+)] )
114
	pulseaudio? ( media-sound/pulseaudio )
115
	rbd? ( sys-cluster/ceph[static-libs(+)] )
116
	sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
117
	sdl? (
118
		!sdl2? (
119
			media-libs/libsdl[X]
120
			>=media-libs/libsdl-1.2.11[static-libs(+)]
121
		)
122
		sdl2? (
123
			media-libs/libsdl2[X]
124
			media-libs/libsdl2[static-libs(+)]
125
		)
126
	)
127
	seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
128
	smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
129
	snappy? ( app-arch/snappy[static-libs(+)] )
130
	spice? (
131
		>=app-emulation/spice-protocol-0.12.3
132
		>=app-emulation/spice-0.12.0[static-libs(+)]
133
	)
134
	ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
135
	usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
136
	usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
137
	uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
138
	vde? ( net-misc/vde[static-libs(+)] )
139
	virgl? ( media-libs/virglrenderer[static-libs(+)] )
140
	virtfs? ( sys-libs/libcap )
141
	xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
142
USER_LIB_DEPEND="${COMMON_LIB_DEPEND}"
143
X86_FIRMWARE_DEPEND="
144
	>=sys-firmware/ipxe-1.0.0_p20130624
145
	pin-upstream-blobs? (
146
		~sys-firmware/seabios-1.8.2
147
		~sys-firmware/sgabios-0.1_pre8
148
		~sys-firmware/vgabios-0.7a
149
	)
150
	!pin-upstream-blobs? (
151
		sys-firmware/seabios
152
		sys-firmware/sgabios
153
		sys-firmware/vgabios
154
	)"
155
CDEPEND="
156
	!static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND//\[static-libs(+)]} ) " ${use_softmmu_targets}) )
157
	!static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND//\[static-libs(+)]} ) " ${use_user_targets}) )
158
	qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
159
	qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
160
	python? ( ${PYTHON_DEPS} )
161
	systemtap? ( dev-util/systemtap )
162
	xen? ( app-emulation/xen-tools:= )"
163
DEPEND="${CDEPEND}
164
	dev-lang/perl
165
	=dev-lang/python-2*
166
	sys-apps/texinfo
167
	virtual/pkgconfig
168
	kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
169
	gtk? ( nls? ( sys-devel/gettext ) )
170
	static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND} ) " ${use_softmmu_targets}) )
171
	static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND} ) " ${use_user_targets}) )
172
	test? (
173
		dev-libs/glib[utils]
174
		sys-devel/bc
175
	)"
176
RDEPEND="${CDEPEND}
177
	selinux? ( sec-policy/selinux-qemu )
178
"
179
180
STRIP_MASK="/usr/share/qemu/palcode-clipper"
181
182
QA_PREBUILT="
183
	usr/share/qemu/openbios-ppc
184
	usr/share/qemu/openbios-sparc64
185
	usr/share/qemu/openbios-sparc32
186
	usr/share/qemu/palcode-clipper
187
	usr/share/qemu/s390-ccw.img
188
	usr/share/qemu/u-boot.e500
189
"
190
191
QA_WX_LOAD="usr/bin/qemu-i386
192
	usr/bin/qemu-x86_64
193
	usr/bin/qemu-alpha
194
	usr/bin/qemu-arm
195
	usr/bin/qemu-cris
196
	usr/bin/qemu-m68k
197
	usr/bin/qemu-microblaze
198
	usr/bin/qemu-microblazeel
199
	usr/bin/qemu-mips
200
	usr/bin/qemu-mipsel
201
	usr/bin/qemu-or32
202
	usr/bin/qemu-ppc
203
	usr/bin/qemu-ppc64
204
	usr/bin/qemu-ppc64abi32
205
	usr/bin/qemu-sh4
206
	usr/bin/qemu-sh4eb
207
	usr/bin/qemu-sparc
208
	usr/bin/qemu-sparc64
209
	usr/bin/qemu-armeb
210
	usr/bin/qemu-sparc32plus
211
	usr/bin/qemu-s390x
212
	usr/bin/qemu-unicore32"
213
214
DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure
215
you have the kernel module loaded before running kvm. The easiest way to
216
ensure that the kernel module is loaded is to load it on boot.\n
217
For AMD CPUs the module is called 'kvm-amd'\n
218
For Intel CPUs the module is called 'kvm-intel'\n
219
Please review /etc/conf.d/modules for how to load these\n\n
220
Make sure your user is in the 'kvm' group\n
221
Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."
222
223
qemu_support_kvm() {
224
	if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
225
		use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
226
		use qemu_softmmu_targets_s390x; then
227
		return 0
228
	fi
229
230
	return 1
231
}
232
233
pkg_pretend() {
234
	if use kernel_linux && kernel_is lt 2 6 25; then
235
		eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
236
	elif use kernel_linux; then
237
		if ! linux_config_exists; then
238
			eerror "Unable to check your kernel for KVM support"
239
		else
240
			CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
241
			ERROR_KVM="You must enable KVM in your kernel to continue"
242
			ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
243
			ERROR_KVM_AMD+=" your kernel configuration."
244
			ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
245
			ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
246
			ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
247
			ERROR_TUN+=" into your kernel or loaded as a module to use the"
248
			ERROR_TUN+=" virtual network device if using -net tap."
249
			ERROR_BRIDGE="You will also need support for 802.1d"
250
			ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
251
			use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
252
			ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
253
			ERROR_VHOST_NET+=" support"
254
255
			if use amd64 || use x86 || use amd64-linux || use x86-linux; then
256
				CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
257
			fi
258
259
			use python && CONFIG_CHECK+=" ~DEBUG_FS"
260
			ERROR_DEBUG_FS="debugFS support required for kvm_stat"
261
262
			# Now do the actual checks setup above
263
			check_extra_config
264
		fi
265
	fi
266
267
	if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
268
		eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
269
		eerror "instances are still pointing to it.  Please update your"
270
		eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
271
		eerror "and the right system binary (e.g. qemu-system-x86_64)."
272
		die "update your virt configs to not use qemu-kvm"
273
	fi
274
}
275
276
pkg_setup() {
277
	enewgroup kvm 78
278
}
279
280
# Sanity check to make sure target lists are kept up-to-date.
281
check_targets() {
282
	local var=$1 mak=$2
283
	local detected sorted
284
285
	pushd "${S}"/default-configs >/dev/null || die
286
287
	# Force C locale until glibc is updated. #564936
288
	detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
289
	sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
290
	if [[ ${sorted} != "${detected}" ]] ; then
291
		eerror "The ebuild needs to be kept in sync."
292
		eerror "${var}: ${sorted}"
293
		eerror "$(printf '%-*s' ${#var} configure): ${detected}"
294
		die "sync ${var} to the list of targets"
295
	fi
296
297
	popd >/dev/null
298
}
299
300
handle_locales() {
301
	# Make sure locale list is kept up-to-date.
302
	local detected sorted
303
	detected=$(echo $(cd po && printf '%s\n' *.po | grep -v messages.po | sed 's:.po$::' | sort -u))
304
	sorted=$(echo $(printf '%s\n' ${PLOCALES} | sort -u))
305
	if [[ ${sorted} != "${detected}" ]] ; then
306
		eerror "The ebuild needs to be kept in sync."
307
		eerror "PLOCALES: ${sorted}"
308
		eerror " po/*.po: ${detected}"
309
		die "sync PLOCALES"
310
	fi
311
312
	# Deal with selective install of locales.
313
	if use nls ; then
314
		# Delete locales the user does not want. #577814
315
		rm_loc() { rm po/$1.po || die; }
316
		l10n_for_each_disabled_locale_do rm_loc
317
	else
318
		# Cheap hack to disable gettext .mo generation.
319
		rm -f po/*.po
320
	fi
321
}
322
323
src_prepare() {
324
	check_targets IUSE_SOFTMMU_TARGETS softmmu
325
	check_targets IUSE_USER_TARGETS linux-user
326
327
	# Alter target makefiles to accept CFLAGS set via flag-o
328
	sed -i -r \
329
		-e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
330
		Makefile Makefile.target || die
331
332
	epatch "${FILESDIR}"/qemu-2.5.0-cflags.patch
333
	[[ -n ${BACKPORTS} ]] && \
334
		EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
335
			epatch
336
337
	epatch "${FILESDIR}"/${P}-CVE-2015-8567.patch #567868
338
	epatch "${FILESDIR}"/${P}-CVE-2015-8558.patch #568246
339
	epatch "${FILESDIR}"/${P}-CVE-2015-8701.patch #570110
340
	epatch "${FILESDIR}"/${P}-CVE-2015-8743.patch #570988
341
	epatch "${FILESDIR}"/${P}-CVE-2016-1568.patch #571566
342
	epatch "${FILESDIR}"/${P}-CVE-2015-8613.patch #569118
343
	epatch "${FILESDIR}"/${P}-CVE-2015-8619.patch #569300
344
	epatch "${FILESDIR}"/${P}-CVE-2016-1714.patch #571560
345
	epatch "${FILESDIR}"/${P}-CVE-2016-1922.patch #572082
346
	epatch "${FILESDIR}"/${P}-CVE-2016-1981.patch #572412
347
	epatch "${FILESDIR}"/${P}-usb-ehci-oob.patch #572454
348
	epatch "${FILESDIR}"/${P}-CVE-2016-2197.patch #573280
349
	epatch "${FILESDIR}"/${P}-CVE-2016-2198.patch #573314
350
	epatch "${FILESDIR}"/${P}-CVE-2016-2392.patch #574902
351
	epatch "${FILESDIR}"/${P}-usb-ndis-int-overflow.patch #575492
352
	epatch "${FILESDIR}"/${P}-rng-stack-corrupt-{0,1,2,3}.patch #576420
353
	epatch "${FILESDIR}"/${P}-sysmacros.patch
354
	epatch "${FILESDIR}"/${P}-ne2000-reg-check.patch #573816
355
	epatch "${FILESDIR}"/${P}-9pfs-segfault.patch #578142
356
357
	# Fix ld and objcopy being called directly
358
	tc-export AR LD OBJCOPY
359
360
	# Verbose builds
361
	MAKEOPTS+=" V=1"
362
363
	epatch_user
364
365
	# Run after we've applied all patches.
366
	handle_locales
367
}
368
369
##
370
# configures qemu based on the build directory and the build type
371
# we are using.
372
#
373
qemu_src_configure() {
374
	debug-print-function ${FUNCNAME} "$@"
375
376
	local buildtype=$1
377
	local builddir="${S}/${buildtype}-build"
378
	local static_flag="static-${buildtype}"
379
380
	mkdir "${builddir}"
381
382
	local conf_opts=(
383
		--prefix=/usr
384
		--sysconfdir=/etc
385
		--libdir=/usr/$(get_libdir)
386
		--docdir=/usr/share/doc/${PF}/html
387
		--disable-bsd-user
388
		--disable-guest-agent
389
		--disable-strip
390
		--disable-werror
391
		# We support gnutls/nettle for crypto operations.  It is possible
392
		# to use gcrypt when gnutls/nettle are disabled (but not when they
393
		# are enabled), but it's not really worth the hassle.  Disable it
394
		# all the time to avoid automatically detecting it. #568856
395
		--disable-gcrypt
396
		--python="${PYTHON}"
397
		--cc="$(tc-getCC)"
398
		--cxx="$(tc-getCXX)"
399
		--host-cc="$(tc-getBUILD_CC)"
400
		$(use_enable debug debug-info)
401
		$(use_enable debug debug-tcg)
402
		--enable-docs
403
		$(use_enable tci tcg-interpreter)
404
		$(use_enable xattr attr)
405
	)
406
407
	# Disable options not used by user targets as the default configure
408
	# options will autoprobe and try to link in a bunch of unused junk.
409
	conf_softmmu() {
410
		if [[ ${buildtype} == "user" ]] ; then
411
			echo "--disable-${2:-$1}"
412
		else
413
			use_enable "$@"
414
		fi
415
	}
416
	conf_opts+=(
417
		$(conf_softmmu accessibility brlapi)
418
		$(conf_softmmu aio linux-aio)
419
		$(conf_softmmu bluetooth bluez)
420
		$(conf_softmmu caps cap-ng)
421
		$(conf_softmmu curl)
422
		$(conf_softmmu fdt)
423
		$(conf_softmmu glusterfs)
424
		$(conf_softmmu gnutls)
425
		$(conf_softmmu gnutls nettle)
426
		$(conf_softmmu gtk)
427
		$(conf_softmmu infiniband rdma)
428
		$(conf_softmmu iscsi libiscsi)
429
		$(conf_softmmu jpeg vnc-jpeg)
430
		$(conf_softmmu kernel_linux kvm)
431
		$(conf_softmmu lzo)
432
		$(conf_softmmu ncurses curses)
433
		$(conf_softmmu nfs libnfs)
434
		$(conf_softmmu numa)
435
		$(conf_softmmu opengl)
436
		$(conf_softmmu png vnc-png)
437
		$(conf_softmmu rbd)
438
		$(conf_softmmu sasl vnc-sasl)
439
		$(conf_softmmu sdl)
440
		$(conf_softmmu seccomp)
441
		$(conf_softmmu smartcard)
442
		$(conf_softmmu snappy)
443
		$(conf_softmmu spice)
444
		$(conf_softmmu ssh libssh2)
445
		$(conf_softmmu usb libusb)
446
		$(conf_softmmu usbredir usb-redir)
447
		$(conf_softmmu uuid)
448
		$(conf_softmmu vde)
449
		$(conf_softmmu vhost-net)
450
		$(conf_softmmu virgl virglrenderer)
451
		$(conf_softmmu virtfs)
452
		$(conf_softmmu vnc)
453
		$(conf_softmmu vte)
454
		$(conf_softmmu xen)
455
		$(conf_softmmu xen xen-pci-passthrough)
456
		$(conf_softmmu xfs xfsctl)
457
	)
458
459
	case ${buildtype} in
460
	user)
461
		conf_opts+=(
462
			--enable-linux-user
463
			--disable-system
464
			--disable-blobs
465
			--disable-tools
466
		)
467
		;;
468
	softmmu)
469
		# audio options
470
		local audio_opts="oss"
471
		use alsa && audio_opts="alsa,${audio_opts}"
472
		use sdl && audio_opts="sdl,${audio_opts}"
473
		use pulseaudio && audio_opts="pa,${audio_opts}"
474
475
		conf_opts+=(
476
			--disable-linux-user
477
			--enable-system
478
			--with-system-pixman
479
			--audio-drv-list="${audio_opts}"
480
		)
481
		use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
482
		use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
483
		;;
484
	tools)
485
		conf_opts+=(
486
			--disable-linux-user
487
			--disable-system
488
			--disable-blobs
489
		)
490
		static_flag="static"
491
		;;
492
	esac
493
494
	local targets="${buildtype}_targets"
495
	[[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
496
497
	# Add support for SystemTAP
498
	use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
499
500
	# We always want to attempt to build with PIE support as it results
501
	# in a more secure binary. But it doesn't work with static or if
502
	# the current GCC doesn't have PIE support.
503
	if use ${static_flag}; then
504
		conf_opts+=( --static --disable-pie )
505
	else
506
		gcc-specs-pie && conf_opts+=( --enable-pie )
507
	fi
508
509
	echo "../configure ${conf_opts[*]}"
510
	cd "${builddir}"
511
	../configure "${conf_opts[@]}" || die "configure failed"
512
513
	# FreeBSD's kernel does not support QEMU assigning/grabbing
514
	# host USB devices yet
515
	use kernel_FreeBSD && \
516
		sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
517
}
518
519
src_configure() {
520
	local target
521
522
	python_setup
523
524
	softmmu_targets= softmmu_bins=()
525
	user_targets= user_bins=()
526
527
	for target in ${IUSE_SOFTMMU_TARGETS} ; do
528
		if use "qemu_softmmu_targets_${target}"; then
529
			softmmu_targets+=",${target}-softmmu"
530
			softmmu_bins+=( "qemu-system-${target}" )
531
		fi
532
	done
533
534
	for target in ${IUSE_USER_TARGETS} ; do
535
		if use "qemu_user_targets_${target}"; then
536
			user_targets+=",${target}-linux-user"
537
			user_bins+=( "qemu-${target}" )
538
		fi
539
	done
540
541
	softmmu_targets=${softmmu_targets#,}
542
	user_targets=${user_targets#,}
543
544
	[[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
545
	[[ -n ${user_targets}    ]] && qemu_src_configure "user"
546
	[[ -z ${softmmu_targets}${user_targets} ]] && qemu_src_configure "tools"
547
}
548
549
src_compile() {
550
	if [[ -n ${user_targets} ]]; then
551
		cd "${S}/user-build"
552
		default
553
	fi
554
555
	if [[ -n ${softmmu_targets} ]]; then
556
		cd "${S}/softmmu-build"
557
		default
558
	fi
559
560
	if [[ -z ${softmmu_targets}${user_targets} ]]; then
561
		cd "${S}/tools-build"
562
		default
563
	fi
564
}
565
566
src_test() {
567
	if [[ -n ${softmmu_targets} ]]; then
568
		cd "${S}/softmmu-build"
569
		pax-mark m */qemu-system-* #515550
570
		emake -j1 check
571
		emake -j1 check-report.html
572
	fi
573
}
574
575
qemu_python_install() {
576
	python_domodule "${S}/scripts/qmp/qmp.py"
577
578
	python_doscript "${S}/scripts/kvm/kvm_stat"
579
	python_doscript "${S}/scripts/kvm/vmxcap"
580
	python_doscript "${S}/scripts/qmp/qmp-shell"
581
	python_doscript "${S}/scripts/qmp/qemu-ga-client"
582
}
583
584
src_install() {
585
	if [[ -n ${user_targets} ]]; then
586
		cd "${S}/user-build"
587
		emake DESTDIR="${ED}" install
588
589
		# Install binfmt handler init script for user targets
590
		exeinto /usr/libexec
591
		doexe "${FILESDIR}"/qemu-binfmt-helper
592
		newinitd "${FILESDIR}/qemu-binfmt.initd-r2" qemu-binfmt
593
		systemd_dounit "${FILESDIR}"/qemu-binfmt.service
594
	fi
595
596
	if [[ -n ${softmmu_targets} ]]; then
597
		cd "${S}/softmmu-build"
598
		emake DESTDIR="${ED}" install
599
600
		# This might not exist if the test failed. #512010
601
		[[ -e check-report.html ]] && dohtml check-report.html
602
603
		if use kernel_linux; then
604
			udev_dorules "${FILESDIR}"/65-kvm.rules
605
		fi
606
607
		if use python; then
608
			python_foreach_impl qemu_python_install
609
		fi
610
	fi
611
612
	if [[ -z ${softmmu_targets}${user_targets} ]]; then
613
		cd "${S}/tools-build"
614
		emake DESTDIR="${ED}" install
615
	fi
616
617
	# Disable mprotect on the qemu binaries as they use JITs to be fast #459348
618
	pushd "${ED}"/usr/bin >/dev/null
619
	pax-mark m "${softmmu_bins[@]}" "${user_bins[@]}"
620
	popd >/dev/null
621
622
	# Install config file example for qemu-bridge-helper
623
	insinto "/etc/qemu"
624
	doins "${FILESDIR}/bridge.conf"
625
626
	# Remove the docdir placed qmp-commands.txt
627
	mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/" || die
628
629
	cd "${S}"
630
	dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
631
	newdoc pc-bios/README README.pc-bios
632
	dodoc docs/qmp-*.txt
633
634
	if [[ -n ${softmmu_targets} ]]; then
635
		# Remove SeaBIOS since we're using the SeaBIOS packaged one
636
		rm "${ED}/usr/share/qemu/bios.bin"
637
		if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
638
			dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
639
		fi
640
641
		# Remove vgabios since we're using the vgabios packaged one
642
		rm "${ED}/usr/share/qemu/vgabios.bin"
643
		rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
644
		rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
645
		rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
646
		rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
647
		if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
648
			dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
649
			dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
650
			dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
651
			dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
652
			dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
653
		fi
654
655
		# Remove sgabios since we're using the sgabios packaged one
656
		rm "${ED}/usr/share/qemu/sgabios.bin"
657
		if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
658
			dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
659
		fi
660
661
		# Remove iPXE since we're using the iPXE packaged one
662
		rm "${ED}"/usr/share/qemu/pxe-*.rom
663
		if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
664
			dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
665
			dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
666
			dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
667
			dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
668
			dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
669
			dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
670
		fi
671
	fi
672
673
	qemu_support_kvm && readme.gentoo_create_doc
674
}
675
676
pkg_postinst() {
677
	if qemu_support_kvm; then
678
		readme.gentoo_print_elog
679
	fi
680
681
	if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
682
		udev_reload
683
	fi
684
685
	fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
686
}
687
688
pkg_info() {
689
	echo "Using:"
690
	echo "  $(best_version app-emulation/spice-protocol)"
691
	echo "  $(best_version sys-firmware/ipxe)"
692
	echo "  $(best_version sys-firmware/seabios)"
693
	if has_version 'sys-firmware/seabios[binary]'; then
694
		echo "    USE=binary"
695
	else
696
		echo "    USE=''"
697
	fi
698
	echo "  $(best_version sys-firmware/vgabios)"
699
}

Return to bug 544150