Revert "qemu: upgrade to 5.0.0"

This reverts commit ba7ed3642fa5e15fe0eeca322a1baabd149ef6e7.

Reason for revert: breaking non-SDK VMs; see https://crbug.com/1114204

Original change's description:
> qemu: upgrade to 5.0.0
>
> Among other things, it fixes some bugs w.r.t. symlink loops in the '-L'
> option:
>
>   https://git.qemu.org/?p=qemu.git;a=commit;h=f3a8bdc1d5b260d31422edd46360ff849dfbcc93
>   util/path: Do not cache all filenames at startup
>
> Retain 'flag-o-matic' (not present upstream) because our bashrc hooks
> try to use it.
>
> BUG=chromium:1099508
> TEST=build; run ARM unit tests for various packages
>
> Cq-Depend: chromium:2278831, chromium:2284214
> Change-Id: Id243a4c90d379dc9221ed16a36744a949f60c253
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2278490
> Tested-by: Brian Norris <briannorris@chromium.org>
> Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
> Reviewed-by: Mike Frysinger <vapier@chromium.org>
> Commit-Queue: Manoj Gupta <manojgupta@chromium.org>

Bug: chromium:1099508, chromium:1114204
Cq-Depend: chromium:2278831
Change-Id: I63bebdd7ce3ae6ab012b987c35f7232c2596d9f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2343463
Commit-Queue: Brian Norris <briannorris@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
diff --git a/app-emulation/qemu/Manifest b/app-emulation/qemu/Manifest
index fa5828b..0c57259 100644
--- a/app-emulation/qemu/Manifest
+++ b/app-emulation/qemu/Manifest
@@ -1 +1 @@
-DIST qemu-5.0.0.tar.xz 62426192 BLAKE2B 785d02ef79c95b5c4f0556186054885f9893d4e8a9f4b4f2d6199a4e1ae9c31d7c79dd900305469217f85d61bbe74134b601d5c6c1b0eee2b74792d010f1fd63 SHA512 21ef0cbe107c468a40f0fa2635db2a40048c8790b629dfffca5cd62bb1b502ea8eb133bfc40df5ecf1489e2bffe87f6829aee041cb8a380ff04a8afa23b39fcf
+DIST qemu-3.0.0.tar.bz2 41491935 SHA256 933e62ad604f5f8d0a93f5e0a98fd95f9d2e23ff1dbd0c744c6c7506bba8ebe8 SHA512 b82b78a063d60fa1372d9400934b47250138c438050d974113b1b2ea433eea0531be6cda1e82d14fcb3bc4ed35657703f62d9aedc095cb8d64badc65c3609ee5 WHIRLPOOL 427382b85035b8058486e9242ba724d5238274f8930865afb9222794e34348fef9b00828e4b7d97e0eb7fd84fd014b9dd4e091ecaf8e22bfecf0e0029c3d1528
diff --git a/app-emulation/qemu/files/qemu-2.11.1-capstone_include_path.patch b/app-emulation/qemu/files/qemu-2.11.1-capstone_include_path.patch
deleted file mode 100644
index d79570e..0000000
--- a/app-emulation/qemu/files/qemu-2.11.1-capstone_include_path.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- qemu-2.11.1/include/disas/capstone.h	2018-02-14 22:53:22.000000000 +0100
-+++ qemu-2.11.1/include/disas/capstone.h	2018-02-17 20:12:12.754703951 +0100
-@@ -3,7 +3,7 @@
- 
- #ifdef CONFIG_CAPSTONE
- 
--#include <capstone.h>
-+#include <capstone/capstone.h>
- 
- #else
- 
diff --git a/app-emulation/qemu/files/qemu-4.0.0-mkdir_systemtap.patch b/app-emulation/qemu/files/qemu-4.0.0-mkdir_systemtap.patch
deleted file mode 100644
index 95ccdd7..0000000
--- a/app-emulation/qemu/files/qemu-4.0.0-mkdir_systemtap.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/Makefile b/Makefile
-index 04a0d450..e0013a59 100644
---- a/Makefile
-+++ b/Makefile
-@@ -803,6 +802,7 @@
- 	$(call install-prog,$(HELPERS-y),$(DESTDIR)$(libexecdir))
- endif
- ifdef CONFIG_TRACE_SYSTEMTAP
-+	mkdir -p $(DESTDIR)$(bindir)
- 	$(INSTALL_PROG) "scripts/qemu-trace-stap" $(DESTDIR)$(bindir)
- endif
- ifneq ($(BLOBS),)
diff --git a/app-emulation/qemu/files/qemu-4.2.0-cflags.patch b/app-emulation/qemu/files/qemu-4.2.0-cflags.patch
deleted file mode 100644
index 1019265..0000000
--- a/app-emulation/qemu/files/qemu-4.2.0-cflags.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git i/configure w/configure
-index a72a5def57..546d757603 100755
---- i/configure
-+++ w/configure
-@@ -6093,10 +6093,6 @@ write_c_skeleton
- if test "$gcov" = "yes" ; then
-   QEMU_CFLAGS="-fprofile-arcs -ftest-coverage -g $QEMU_CFLAGS"
-   QEMU_LDFLAGS="-fprofile-arcs -ftest-coverage $QEMU_LDFLAGS"
--elif test "$fortify_source" = "yes" ; then
--  CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS"
--elif test "$debug" = "no"; then
--  CFLAGS="-O2 $CFLAGS"
- fi
- 
- if test "$have_asan" = "yes"; then
-
diff --git a/app-emulation/qemu/files/qemu-5.0.0-epoll-strace.patch b/app-emulation/qemu/files/qemu-5.0.0-epoll-strace.patch
deleted file mode 100644
index c0f9a2e..0000000
--- a/app-emulation/qemu/files/qemu-5.0.0-epoll-strace.patch
+++ /dev/null
@@ -1,50 +0,0 @@
-https://lists.nongnu.org/archive/html/qemu-devel/2020-04/msg02643.html
-
-From 6bce23d8daf96a7faa9288e7414948cda31ddaa2 Mon Sep 17 00:00:00 2001
-From: Sergei Trofimovich <slyfox@gentoo.org>
-Date: Thu, 16 Apr 2020 18:55:49 +0100
-Subject: [PATCH] linux-user/strace.list: fix epoll_create{,1} -strace output
-
-Fix syscall name and parameters priinter.
-
-Before the change:
-
-```
-$ alpha-linux-user/qemu-alpha -strace -L /usr/alpha-unknown-linux-gnu/ /tmp/a
-...
-1274697 %s(%d)(2097152,274903156744,274903156760,274905840712,274877908880,274903235616) = 3
-1274697 exit_group(0)
-```
-
-After the change:
-
-```
-$ alpha-linux-user/qemu-alpha -strace -L /usr/alpha-unknown-linux-gnu/ /tmp/a
-...
-1273719 epoll_create1(2097152) = 3
-1273719 exit_group(0)
-```
-
-Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
----
- linux-user/strace.list | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
---- a/linux-user/strace.list
-+++ b/linux-user/strace.list
-@@ -125,10 +125,10 @@
- { TARGET_NR_dup3, "dup3" , "%s(%d,%d,%d)", NULL, NULL },
- #endif
- #ifdef TARGET_NR_epoll_create
--{ TARGET_NR_epoll_create, "%s(%d)", NULL, NULL, NULL },
-+{ TARGET_NR_epoll_create, "epoll_create", "%s(%d)", NULL, NULL },
- #endif
- #ifdef TARGET_NR_epoll_create1
--{ TARGET_NR_epoll_create1, "%s(%d)", NULL, NULL, NULL },
-+{ TARGET_NR_epoll_create1, "epoll_create1", "%s(%d)", NULL, NULL },
- #endif
- #ifdef TARGET_NR_epoll_ctl
- { TARGET_NR_epoll_ctl, "epoll_ctl" , NULL, NULL, NULL },
--- 
-2.26.2
-
diff --git a/app-emulation/qemu/files/qemu-binfmt.initd.head b/app-emulation/qemu/files/qemu-binfmt.initd.head
index 832ddb0..858d5d7 100644
--- a/app-emulation/qemu/files/qemu-binfmt.initd.head
+++ b/app-emulation/qemu/files/qemu-binfmt.initd.head
@@ -1,5 +1,5 @@
 #!/sbin/openrc-run
-# Copyright 1999-2018 Gentoo Authors
+# Copyright 1999-2017 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 # Enable automatic non-native program execution by the kernel.
diff --git a/app-emulation/qemu/metadata.xml b/app-emulation/qemu/metadata.xml
index 0c30c45..680e203 100644
--- a/app-emulation/qemu/metadata.xml
+++ b/app-emulation/qemu/metadata.xml
@@ -5,10 +5,6 @@
 		<email>tamiko@gentoo.org</email>
 		<name>Matthias Maier</name>
 	</maintainer>
-	<maintainer type="person">
-		<email>slyfox@gentoo.org</email>
-		<name>Sergei Trofimovich</name>
-	</maintainer>
 	<maintainer type="project">
 		<email>virtualization@gentoo.org</email>
 		<name>Gentoo Virtualization Project</name>
@@ -25,35 +21,33 @@
 		<flag name="gnutls">Enable TLS support for the VNC console server.
 		For 1.4 and newer this also enables WebSocket support.
 		For 2.0 through 2.3 also enables disk quorum support.</flag>
+		<flag name="gtk2">Use gtk-2 instead of gtk-3</flag>
 		<flag name="iscsi">Enable direct iSCSI support via
 		<pkg>net-libs/libiscsi</pkg> instead of indirectly via the Linux
 		block layer that <pkg>sys-block/open-iscsi</pkg> does.</flag>
-		<flag name="io-uring">Enable efficient I/O via <pkg>sys-libs/liburing</pkg>.</flag>
 		<flag name="ncurses">Enable the ncurses-based console</flag>
 		<flag name="nfs">Enable NFS support</flag>
 		<flag name="numa">Enable NUMA support</flag>
 		<flag name="pin-upstream-blobs">Pin the versions of BIOS firmware to the version included in the upstream release.
 		This is needed to sanely support migration/suspend/resume/snapshotting/etc... of instances.
 		When the blobs are different, random corruption/bugs/crashes/etc... may be observed.</flag>
-		<flag name="plugins">Enable qemu plugin API via shared library loading.</flag>
 		<flag name="pulseaudio">Enable pulseaudio output for sound emulation</flag>
 		<flag name="rbd">Enable rados block device backend support, see http://ceph.newdream.net/wiki/QEMU-RBD</flag>
 		<flag name="sdl">Enable the SDL-based console</flag>
-		<flag name="sdl-image">SDL Image support for icons</flag>
+		<flag name="sdl2">Use libsdl2 instead of libsdl</flag>
 		<flag name="spice">Enable Spice protocol support via <pkg>app-emulation/spice</pkg></flag>
 		<flag name="ssh">Enable SSH based block device support via <pkg>net-libs/libssh2</pkg></flag>
 		<flag name="static-user">Build the User targets as static binaries</flag>
 		<flag name="static">Build the User and Software MMU (system) targets as well as tools as static binaries</flag>
+		<flag name="snappy">Enable support for snappy compression</flag>
 		<flag name="systemtap">Enable SystemTAP/DTrace tracing</flag>
 		<flag name="tci">Enable the TCG Interpreter which can speed up or slowdown workloads depending on the host and guest CPUs being emulated. In the future it will be a runtime option but for now its compile time.</flag>
-		<flag name="jemalloc">Enable jemalloc allocator support</flag>
 		<flag name="jpeg">Enable jpeg image support for the VNC console server</flag>
 		<flag name="png">Enable png image support for the VNC console server</flag>
 		<flag name="usb">Enable USB passthrough via <pkg>dev-libs/libusb</pkg></flag>
 		<flag name="usbredir">Use <pkg>sys-apps/usbredir</pkg> to redirect USB devices to another machine over TCP</flag>
 		<flag name="vde">Enable VDE-based networking</flag>
 		<flag name="vhost-net">Enable accelerated networking using vhost-net, see http://www.linux-kvm.org/page/VhostNet</flag>
-		<flag name="vhost-user-fs">Enable shared file system access using the FUSE protocol carried over virtio.</flag>
 		<flag name="virgl">Enable experimental Virgil 3d (virtual software GPU)</flag>
 		<flag name="virtfs">Enable VirtFS via virtio-9p-pci / fsdev. See http://wiki.qemu.org/Documentation/9psetup</flag>
 		<flag name="vte">Enable terminal support (<pkg>x11-libs/vte</pkg>) in the GTK+ interface</flag>
@@ -63,6 +57,5 @@
 		<flag name="xen">Enables support for Xen backends</flag>
 		<flag name="xfs">Support xfsctl() notification and syncing for XFS backed
 		virtual disks.</flag>
-		<flag name="xkb">Depend on x11-libs/libxkbcommon to build qemu-keymap tool for converting xkb keymaps</flag>
 	</use>
 </pkgmetadata>
diff --git a/app-emulation/qemu/qemu-3.0.0-r3.ebuild b/app-emulation/qemu/qemu-3.0.0-r3.ebuild
new file mode 120000
index 0000000..38d37a7
--- /dev/null
+++ b/app-emulation/qemu/qemu-3.0.0-r3.ebuild
@@ -0,0 +1 @@
+qemu-3.0.0.ebuild
\ No newline at end of file
diff --git a/app-emulation/qemu/qemu-5.0.0.ebuild b/app-emulation/qemu/qemu-3.0.0.ebuild
similarity index 85%
rename from app-emulation/qemu/qemu-5.0.0.ebuild
rename to app-emulation/qemu/qemu-3.0.0.ebuild
index e9a6e15..f50fbdf 100644
--- a/app-emulation/qemu/qemu-5.0.0.ebuild
+++ b/app-emulation/qemu/qemu-3.0.0.ebuild
@@ -1,30 +1,28 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-EAPI="7"
+EAPI="6"
 
-PYTHON_COMPAT=( python{3_6,3_7,3_8} )
+PYTHON_COMPAT=( python{2_7,3_4,3_5,3_6} )
 PYTHON_REQ_USE="ncurses,readline"
 
 PLOCALES="bg de_DE fr_FR hu it tr zh_CN"
 
-FIRMWARE_ABI_VERSION="4.0.0-r50"
+FIRMWARE_ABI_VERSION="2.11.1-r50"
 
 inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
-	udev fcaps readme.gentoo-r1 pax-utils l10n xdg-utils
+	user udev fcaps readme.gentoo-r1 pax-utils l10n versionator
 
 if [[ ${PV} = *9999* ]]; then
-	EGIT_REPO_URI="https://git.qemu.org/git/qemu.git"
-	EGIT_SUBMODULES=(
-		slirp
-		tests/fp/berkeley-{test,soft}float-3
-		ui/keycodemapdb
-	)
+	EGIT_REPO_URI="git://git.qemu.org/qemu.git"
 	inherit git-r3
 	SRC_URI=""
 else
-	SRC_URI="https://download.qemu.org/${P}.tar.xz"
+	SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2"
 	KEYWORDS="*"
+
+	# Gentoo specific patchsets:
+	#SRC_URI+=" https://dev.gentoo.org/~tamiko/distfiles/${P}-patches-r1.tar.xz"
 fi
 
 DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
@@ -32,21 +30,18 @@
 
 LICENSE="GPL-2 LGPL-2 BSD-2"
 SLOT="0"
-
-IUSE="accessibility +aio alsa bzip2 capstone +caps +curl debug doc
-	+fdt glusterfs gnutls gtk infiniband iscsi io-uring
-	jemalloc +jpeg kernel_linux
-	kernel_FreeBSD lzo ncurses nfs nls numa opengl +oss +pin-upstream-blobs
-	plugins +png pulseaudio python rbd sasl +seccomp sdl sdl-image selinux
-	smartcard snappy spice ssh static static-user systemtap tci test usb
-	usbredir vde +vhost-net vhost-user-fs virgl virtfs +vnc vte xattr xen
-	xfs +xkb zstd"
+IUSE="accessibility +aio alsa bluetooth bzip2 capstone +caps +curl debug
+	+fdt glusterfs gnutls gtk gtk2 infiniband iscsi +jpeg kernel_linux
+	kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs +png
+	pulseaudio python rbd sasl +seccomp sdl sdl2 selinux smartcard snappy
+	spice ssh static static-user systemtap tci test usb usbredir vde
+	+vhost-net virgl virtfs +vnc vte xattr xen xfs"
 
 COMMON_TARGETS="aarch64 alpha arm cris hppa i386 m68k microblaze microblazeel
 	mips mips64 mips64el mipsel nios2 or1k ppc ppc64 riscv32 riscv64 s390x
 	sh4 sh4eb sparc sparc64 x86_64 xtensa xtensaeb"
 IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS}
-	lm32 moxie rx tricore unicore32"
+	lm32 moxie ppcemb tricore unicore32"
 IUSE_USER_TARGETS="${COMMON_TARGETS}
 	aarch64_be armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus
 	tilegx"
@@ -55,23 +50,19 @@
 use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
 IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
 
-RESTRICT="!test? ( test )"
 # Allow no targets to be built so that people can get a tools-only build.
 # Block USE flag configurations known to not work.
 REQUIRED_USE="${PYTHON_REQUIRED_USE}
+	gtk2? ( gtk )
 	qemu_softmmu_targets_arm? ( fdt )
 	qemu_softmmu_targets_microblaze? ( fdt )
 	qemu_softmmu_targets_mips64el? ( fdt )
-	qemu_softmmu_targets_ppc64? ( fdt )
 	qemu_softmmu_targets_ppc? ( fdt )
-	qemu_softmmu_targets_riscv32? ( fdt )
-	qemu_softmmu_targets_riscv64? ( fdt )
-	static? ( static-user !alsa !gtk !opengl !pulseaudio !plugins !rbd !snappy )
-	static-user? ( !plugins )
+	qemu_softmmu_targets_ppc64? ( fdt )
+	sdl2? ( sdl )
+	static? ( static-user !alsa !bluetooth !gtk !gtk2 !opengl !pulseaudio !snappy )
 	virtfs? ( xattr )
-	vte? ( gtk )
-	plugins? ( !static !static-user )
-"
+	vte? ( gtk )"
 
 # Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
 # and user/softmmu targets (qemu-*, qemu-system-*).
@@ -92,7 +83,7 @@
 # softmmu targets (qemu-system-*).
 SOFTMMU_TOOLS_DEPEND="
 	dev-libs/libxml2[static-libs(+)]
-	xkb? ( x11-libs/libxkbcommon[static-libs(+)] )
+	x11-libs/libxkbcommon[static-libs(+)]
 	>=x11-libs/pixman-0.28.0[static-libs(+)]
 	accessibility? (
 		app-accessibility/brltty[api]
@@ -100,19 +91,26 @@
 	)
 	aio? ( dev-libs/libaio[static-libs(+)] )
 	alsa? ( >=media-libs/alsa-lib-1.0.13 )
+	bluetooth? ( net-wireless/bluez )
 	bzip2? ( app-arch/bzip2[static-libs(+)] )
-	capstone? ( dev-libs/capstone:= )
+	capstone? ( dev-libs/capstone )
 	caps? ( sys-libs/libcap-ng[static-libs(+)] )
 	curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
-	fdt? ( >=sys-apps/dtc-1.5.0[static-libs(+)] )
+	fdt? ( >=sys-apps/dtc-1.4.2[static-libs(+)] )
 	glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
 	gnutls? (
 		dev-libs/nettle:=[static-libs(+)]
 		>=net-libs/gnutls-3.0:=[static-libs(+)]
 	)
 	gtk? (
-		x11-libs/gtk+:3
-		vte? ( x11-libs/vte:2.91 )
+		gtk2? (
+			x11-libs/gtk+:2
+			vte? ( x11-libs/vte:0 )
+		)
+		!gtk2? (
+			x11-libs/gtk+:3
+			vte? ( x11-libs/vte:2.91 )
+		)
 	)
 	infiniband? (
 		sys-fabric/libibumad:=[static-libs(+)]
@@ -120,8 +118,6 @@
 		sys-fabric/librdmacm:=[static-libs(+)]
 	)
 	iscsi? ( net-libs/libiscsi )
-	io-uring? ( sys-libs/liburing[static-libs(+)] )
-	jemalloc? ( dev-libs/jemalloc )
 	jpeg? ( virtual/jpeg:0=[static-libs(+)] )
 	lzo? ( dev-libs/lzo:2[static-libs(+)] )
 	ncurses? (
@@ -138,13 +134,18 @@
 	)
 	png? ( media-libs/libpng:0=[static-libs(+)] )
 	pulseaudio? ( media-sound/pulseaudio )
-	rbd? ( sys-cluster/ceph )
+	rbd? ( sys-cluster/ceph[static-libs(+)] )
 	sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
 	sdl? (
-		media-libs/libsdl2[video]
-		media-libs/libsdl2[static-libs(+)]
+		!sdl2? (
+			media-libs/libsdl[X]
+			>=media-libs/libsdl-1.2.11[static-libs(+)]
+		)
+		sdl2? (
+			media-libs/libsdl2[X]
+			media-libs/libsdl2[static-libs(+)]
+		)
 	)
-	sdl-image? ( media-libs/sdl2-image[static-libs(+)] )
 	seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
 	smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
 	snappy? ( app-arch/snappy:= )
@@ -152,22 +153,20 @@
 		>=app-emulation/spice-protocol-0.12.3
 		>=app-emulation/spice-0.12.0[static-libs(+)]
 	)
-	ssh? ( >=net-libs/libssh-0.8.6[static-libs(+)] )
+	ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
 	usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
 	usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
 	vde? ( net-misc/vde[static-libs(+)] )
 	virgl? ( media-libs/virglrenderer[static-libs(+)] )
 	virtfs? ( sys-libs/libcap )
 	xen? ( app-emulation/xen-tools:= )
-	xfs? ( sys-fs/xfsprogs[static-libs(+)] )
-	zstd? ( >=app-arch/zstd-1.4.0[static-libs(+)] )
-"
+	xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
 
 X86_FIRMWARE_DEPEND="
 	pin-upstream-blobs? (
-		~sys-firmware/edk2-ovmf-201905[binary]
-		~sys-firmware/ipxe-1.0.0_p20190728[binary]
-		~sys-firmware/seabios-1.12.0[binary,seavgabios]
+		~sys-firmware/edk2-ovmf-2017_p20180211[binary]
+		~sys-firmware/ipxe-1.0.0_p20180211[binary]
+		~sys-firmware/seabios-1.11.0[binary,seavgabios]
 		~sys-firmware/sgabios-0.1_pre8[binary]
 	)
 	!pin-upstream-blobs? (
@@ -178,25 +177,13 @@
 	)"
 PPC64_FIRMWARE_DEPEND="
 	pin-upstream-blobs? (
-		~sys-firmware/seabios-1.12.0[binary,seavgabios]
+		~sys-firmware/seabios-1.11.0[binary,seavgabios]
 	)
 	!pin-upstream-blobs? (
 		>=sys-firmware/seabios-1.10.2[seavgabios]
 	)
 "
 
-BDEPEND="
-	$(python_gen_impl_dep)
-	dev-lang/perl
-	sys-apps/texinfo
-	virtual/pkgconfig
-	doc? ( dev-python/sphinx )
-	gtk? ( nls? ( sys-devel/gettext ) )
-	test? (
-		dev-libs/glib[utils]
-		sys-devel/bc
-	)
-"
 CDEPEND="
 	!static? (
 		${ALL_DEPEND//\[static-libs(+)]}
@@ -207,22 +194,26 @@
 	qemu_softmmu_targets_ppc64? ( ${PPC64_FIRMWARE_DEPEND} )
 "
 DEPEND="${CDEPEND}
+	${PYTHON_DEPS}
+	dev-lang/perl
+	=dev-lang/python-2*
+	sys-apps/texinfo
+	virtual/pkgconfig
 	kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
+	gtk? ( nls? ( sys-devel/gettext ) )
 	static? (
 		${ALL_DEPEND}
 		${SOFTMMU_TOOLS_DEPEND}
 	)
-	static-user? ( ${ALL_DEPEND} )"
+	static-user? ( ${ALL_DEPEND} )
+	test? (
+		dev-libs/glib[utils]
+		sys-devel/bc
+	)"
 RDEPEND="${CDEPEND}
-	acct-group/kvm
 	selinux? ( sec-policy/selinux-qemu )"
 
-PATCHES=(
-	"${FILESDIR}"/${PN}-2.11.1-capstone_include_path.patch
-	"${FILESDIR}"/${PN}-4.0.0-mkdir_systemtap.patch #684902
-	"${FILESDIR}"/${PN}-4.2.0-cflags.patch
-	"${FILESDIR}"/${PN}-5.0.0-epoll-strace.patch
-)
+STRIP_MASK="/usr/share/qemu/palcode-clipper"
 
 QA_PREBUILT="
 	usr/share/qemu/hppa-firmware.img
@@ -325,6 +316,10 @@
 	fi
 }
 
+pkg_setup() {
+	enewgroup kvm 78
+}
+
 # Sanity check to make sure target lists are kept up-to-date.
 check_targets() {
 	local var=$1 mak=$2
@@ -372,11 +367,15 @@
 	check_targets IUSE_SOFTMMU_TARGETS softmmu
 	check_targets IUSE_USER_TARGETS linux-user
 
+	# Alter target makefiles to accept CFLAGS set via flag-o
+	sed -i -r \
+		-e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
+		Makefile Makefile.target || die
+
 	default
 
-	# Use correct toolchain to fix cross-compiling
-	tc-export AR AS LD NM OBJCOPY PKG_CONFIG RANLIB
-	export WINDRES=${CHOST}-windres
+	# Fix ld and objcopy being called directly
+	tc-export AR LD OBJCOPY PKG_CONFIG
 
 	# Verbose builds
 	MAKEOPTS+=" V=1"
@@ -403,13 +402,8 @@
 	local conf_opts=(
 		--prefix=/usr
 		--sysconfdir=/etc
-		--bindir=/usr/bin
 		--libdir=/usr/$(get_libdir)
-		--datadir=/usr/share
 		--docdir=/usr/share/doc/${PF}/html
-		--mandir=/usr/share/man
-		--with-confsuffix=/qemu
-		--localstatedir=/var
 		--disable-bsd-user
 		--disable-guest-agent
 		--disable-strip
@@ -425,8 +419,7 @@
 		--host-cc="$(tc-getBUILD_CC)"
 		$(use_enable debug debug-info)
 		$(use_enable debug debug-tcg)
-		$(use_enable doc docs)
-		$(use_enable plugins)
+		--enable-docs
 		$(use_enable tci tcg-interpreter)
 		$(use_enable xattr attr)
 	)
@@ -444,6 +437,7 @@
 		$(conf_notuser accessibility brlapi)
 		$(conf_notuser aio linux-aio)
 		$(conf_notuser bzip2)
+		$(conf_notuser bluetooth bluez)
 		$(conf_notuser capstone)
 		$(conf_notuser caps cap-ng)
 		$(conf_notuser curl)
@@ -454,8 +448,6 @@
 		$(conf_notuser gtk)
 		$(conf_notuser infiniband rdma)
 		$(conf_notuser iscsi libiscsi)
-		$(conf_notuser io-uring linux-io-uring)
-		$(conf_notuser jemalloc jemalloc)
 		$(conf_notuser jpeg vnc-jpeg)
 		$(conf_notuser kernel_linux kvm)
 		$(conf_notuser lzo)
@@ -467,17 +459,15 @@
 		$(conf_notuser rbd)
 		$(conf_notuser sasl vnc-sasl)
 		$(conf_notuser sdl)
-		$(conf_notuser sdl-image)
 		$(conf_notuser seccomp)
 		$(conf_notuser smartcard)
 		$(conf_notuser snappy)
 		$(conf_notuser spice)
-		$(conf_notuser ssh libssh)
+		$(conf_notuser ssh libssh2)
 		$(conf_notuser usb libusb)
 		$(conf_notuser usbredir usb-redir)
 		$(conf_notuser vde)
 		$(conf_notuser vhost-net)
-		$(conf_notuser vhost-user-fs)
 		$(conf_notuser virgl virglrenderer)
 		$(conf_notuser virtfs)
 		$(conf_notuser vnc)
@@ -485,8 +475,6 @@
 		$(conf_notuser xen)
 		$(conf_notuser xen xen-pci-passthrough)
 		$(conf_notuser xfs xfsctl)
-		$(conf_notuser xkb xkbcommon)
-		$(conf_notuser zstd)
 	)
 
 	if [[ ${buildtype} == "user" ]] ; then
@@ -497,17 +485,15 @@
 
 	if [[ ! ${buildtype} == "user" ]] ; then
 		# audio options
-		local audio_opts=(
-			# Note: backend order matters here: #716202
-			# We iterate from higher-level to lower level.
-			$(usex pulseaudio pa "")
-			$(usev sdl)
-			$(usev alsa)
-			$(usev oss)
-		)
+		local audio_opts="oss"
+		use alsa && audio_opts="alsa,${audio_opts}"
+		use sdl && audio_opts="sdl,${audio_opts}"
+		use pulseaudio && audio_opts="pa,${audio_opts}"
 		conf_opts+=(
-			--audio-drv-list=$(printf "%s," "${audio_opts[@]}")
+			--audio-drv-list="${audio_opts}"
 		)
+		use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
+		use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
 	fi
 
 	case ${buildtype} in
@@ -613,12 +599,13 @@
 	if [[ -n ${softmmu_targets} ]]; then
 		cd "${S}/softmmu-build"
 		pax-mark m */qemu-system-* #515550
-		emake check
+		emake -j1 check
+		emake -j1 check-report.html
 	fi
 }
 
 qemu_python_install() {
-	python_domodule "${S}/python/qemu"
+	python_domodule "${S}/scripts/qmp/qmp.py"
 
 	python_doscript "${S}/scripts/kvm/vmxcap"
 	python_doscript "${S}/scripts/qmp/qmp-shell"
@@ -664,11 +651,9 @@
 		sparc*) qcpu="sparc";;
 		esac
 
-		# we use 'printf' here to be portable across 'sh'
-		# implementations: #679168
 		cat <<EOF >>"${out}"
 	if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then
-		printf '%s\n' ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
+		echo ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
 	fi
 EOF
 
@@ -697,7 +682,7 @@
 		emake DESTDIR="${ED}" install
 
 		# This might not exist if the test failed. #512010
-		[[ -e check-report.html ]] && dodoc check-report.html
+		[[ -e check-report.html ]] && dohtml check-report.html
 
 		if use kernel_linux; then
 			udev_newrules "${FILESDIR}"/65-kvm.rules-r1 65-kvm.rules
@@ -724,9 +709,6 @@
 	dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
 	newdoc pc-bios/README README.pc-bios
 
-	# Disallow stripping of prebuilt firmware files.
-	dostrip -x ${QA_PREBUILT}
-
 	if [[ -n ${softmmu_targets} ]]; then
 		# Remove SeaBIOS since we're using the SeaBIOS packaged one
 		rm "${ED}/usr/share/qemu/bios.bin"
@@ -778,7 +760,7 @@
 firmware_abi_change() {
 	local pv
 	for pv in ${REPLACING_VERSIONS}; do
-		if ver_test $pv -lt ${FIRMWARE_ABI_VERSION}; then
+		if ! version_is_at_least ${FIRMWARE_ABI_VERSION} ${pv}; then
 			return 0
 		fi
 	done
@@ -790,10 +772,7 @@
 		udev_reload
 	fi
 
-	xdg_icon_cache_update
-
-	[[ -z ${EPREFIX} ]] && [[ -f ${EROOT}/usr/libexec/qemu-bridge-helper ]] && \
-		fcaps cap_net_admin ${EROOT}/usr/libexec/qemu-bridge-helper
+	fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
 
 	DISABLE_AUTOFORMATTING=true
 	readme.gentoo_print_elog
@@ -831,7 +810,3 @@
 	fi
 	echo "  $(best_version sys-firmware/sgabios)"
 }
-
-pkg_postrm() {
-	xdg_icon_cache_update
-}
diff --git a/profiles/categories b/profiles/categories
index 4558958..c4a72bf 100644
--- a/profiles/categories
+++ b/profiles/categories
@@ -1,4 +1,3 @@
-acct-group
 app-accessibility
 app-admin
 app-antivirus