Gentoo Archives: gentoo-commits

From: Jory Pratt <anarchy@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/musl:master commit in: app-emulation/qemu/
Date: Thu, 29 Apr 2021 15:41:18
Message-Id: 1619710866.196c5a46785b3a60787571eae348c6f8ca5fee22.anarchy@gentoo
1 commit: 196c5a46785b3a60787571eae348c6f8ca5fee22
2 Author: Jory Pratt <anarchy <AT> gentoo <DOT> org>
3 AuthorDate: Thu Apr 29 15:41:06 2021 +0000
4 Commit: Jory Pratt <anarchy <AT> gentoo <DOT> org>
5 CommitDate: Thu Apr 29 15:41:06 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/musl.git/commit/?id=196c5a46
7
8 app-emulation/qemu: sync with ::gentoo
9
10 Package-Manager: Portage-3.0.18, Repoman-3.0.2
11 Signed-off-by: Jory Pratt <anarchy <AT> gentoo.org>
12
13 app-emulation/qemu/qemu-5.2.0-r3.ebuild | 886 ++++++++++++++++++++++++++++++++
14 1 file changed, 886 insertions(+)
15
16 diff --git a/app-emulation/qemu/qemu-5.2.0-r3.ebuild b/app-emulation/qemu/qemu-5.2.0-r3.ebuild
17 new file mode 100644
18 index 0000000..8234a3c
19 --- /dev/null
20 +++ b/app-emulation/qemu/qemu-5.2.0-r3.ebuild
21 @@ -0,0 +1,886 @@
22 +# Copyright 1999-2021 Gentoo Authors
23 +# Distributed under the terms of the GNU General Public License v2
24 +
25 +EAPI="7"
26 +
27 +PYTHON_COMPAT=( python3_{7,8,9} )
28 +PYTHON_REQ_USE="ncurses,readline"
29 +
30 +FIRMWARE_ABI_VERSION="4.0.0-r50"
31 +
32 +inherit eutils linux-info toolchain-funcs multilib python-r1
33 +inherit udev fcaps readme.gentoo-r1 pax-utils l10n xdg-utils
34 +inherit flag-o-matic
35 +
36 +if [[ ${PV} = *9999* ]]; then
37 + EGIT_REPO_URI="https://git.qemu.org/git/qemu.git"
38 + EGIT_SUBMODULES=(
39 + meson
40 + tests/fp/berkeley-softfloat-3
41 + tests/fp/berkeley-testfloat-3
42 + ui/keycodemapdb
43 + )
44 + inherit git-r3
45 + SRC_URI=""
46 +else
47 + SRC_URI="https://download.qemu.org/${P}.tar.xz"
48 + KEYWORDS="amd64 arm64 ~ppc ~ppc64 ~x86"
49 +fi
50 +
51 +DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
52 +HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
53 +
54 +LICENSE="GPL-2 LGPL-2 BSD-2"
55 +SLOT="0"
56 +
57 +IUSE="accessibility +aio alsa bzip2 capstone +caps +curl debug +doc
58 + +fdt glusterfs gnutls gtk infiniband iscsi io-uring
59 + jack jemalloc +jpeg kernel_linux
60 + kernel_FreeBSD lzo multipath
61 + ncurses nfs nls numa opengl +oss +pin-upstream-blobs
62 + plugins +png pulseaudio python rbd sasl +seccomp sdl sdl-image selinux
63 + +slirp
64 + smartcard snappy spice ssh static static-user systemtap test udev usb
65 + usbredir vde +vhost-net vhost-user-fs virgl virtfs +vnc vte xattr xen
66 + xfs zstd"
67 +
68 +COMMON_TARGETS="aarch64 alpha arm cris hppa i386 m68k microblaze microblazeel
69 + mips mips64 mips64el mipsel nios2 or1k ppc ppc64 riscv32 riscv64 s390x
70 + sh4 sh4eb sparc sparc64 x86_64 xtensa xtensaeb"
71 +IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS}
72 + avr lm32 moxie rx tricore unicore32"
73 +IUSE_USER_TARGETS="${COMMON_TARGETS}
74 + aarch64_be armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus
75 + tilegx"
76 +
77 +use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
78 +use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
79 +IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
80 +
81 +RESTRICT="!test? ( test )"
82 +# Allow no targets to be built so that people can get a tools-only build.
83 +# Block USE flag configurations known to not work.
84 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
85 + qemu_softmmu_targets_arm? ( fdt )
86 + qemu_softmmu_targets_microblaze? ( fdt )
87 + qemu_softmmu_targets_mips64el? ( fdt )
88 + qemu_softmmu_targets_ppc64? ( fdt )
89 + qemu_softmmu_targets_ppc? ( fdt )
90 + qemu_softmmu_targets_riscv32? ( fdt )
91 + qemu_softmmu_targets_riscv64? ( fdt )
92 + static? ( static-user !alsa !gtk !jack !opengl !pulseaudio !plugins !rbd !snappy )
93 + static-user? ( !plugins )
94 + vhost-user-fs? ( caps seccomp )
95 + virtfs? ( caps xattr )
96 + vte? ( gtk )
97 + multipath? ( udev )
98 + plugins? ( !static !static-user )
99 +"
100 +
101 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
102 +# and user/softmmu targets (qemu-*, qemu-system-*).
103 +#
104 +# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
105 +#
106 +# The attr lib isn't always linked in (although the USE flag is always
107 +# respected). This is because qemu supports using the C library's API
108 +# when available rather than always using the external library.
109 +ALL_DEPEND="
110 + >=dev-libs/glib-2.0[static-libs(+)]
111 + sys-libs/zlib[static-libs(+)]
112 + python? ( ${PYTHON_DEPS} )
113 + systemtap? ( dev-util/systemtap )
114 + xattr? ( sys-apps/attr[static-libs(+)] )"
115 +
116 +# Dependencies required for qemu tools (qemu-nbd, qemu-img, qemu-io, ...)
117 +# softmmu targets (qemu-system-*).
118 +SOFTMMU_TOOLS_DEPEND="
119 + dev-libs/libxml2[static-libs(+)]
120 + >=x11-libs/pixman-0.28.0[static-libs(+)]
121 + accessibility? (
122 + app-accessibility/brltty[api]
123 + app-accessibility/brltty[static-libs(+)]
124 + )
125 + aio? ( dev-libs/libaio[static-libs(+)] )
126 + alsa? ( >=media-libs/alsa-lib-1.0.13 )
127 + bzip2? ( app-arch/bzip2[static-libs(+)] )
128 + capstone? ( dev-libs/capstone:= )
129 + caps? ( sys-libs/libcap-ng[static-libs(+)] )
130 + curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
131 + fdt? ( >=sys-apps/dtc-1.5.0[static-libs(+)] )
132 + glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
133 + gnutls? (
134 + dev-libs/nettle:=[static-libs(+)]
135 + >=net-libs/gnutls-3.0:=[static-libs(+)]
136 + )
137 + gtk? (
138 + x11-libs/gtk+:3
139 + vte? ( x11-libs/vte:2.91 )
140 + )
141 + infiniband? (
142 + sys-fabric/libibumad:=[static-libs(+)]
143 + sys-fabric/libibverbs:=[static-libs(+)]
144 + sys-fabric/librdmacm:=[static-libs(+)]
145 + )
146 + iscsi? ( net-libs/libiscsi )
147 + io-uring? ( sys-libs/liburing:=[static-libs(+)] )
148 + jack? ( virtual/jack )
149 + jemalloc? ( dev-libs/jemalloc )
150 + jpeg? ( virtual/jpeg:0=[static-libs(+)] )
151 + lzo? ( dev-libs/lzo:2[static-libs(+)] )
152 + multipath? ( sys-fs/multipath-tools )
153 + ncurses? (
154 + sys-libs/ncurses:0=[unicode]
155 + sys-libs/ncurses:0=[static-libs(+)]
156 + )
157 + nfs? ( >=net-fs/libnfs-1.9.3:=[static-libs(+)] )
158 + numa? ( sys-process/numactl[static-libs(+)] )
159 + opengl? (
160 + virtual/opengl
161 + media-libs/libepoxy[static-libs(+)]
162 + media-libs/mesa[static-libs(+)]
163 + media-libs/mesa[egl,gbm]
164 + )
165 + png? ( media-libs/libpng:0=[static-libs(+)] )
166 + pulseaudio? ( media-sound/pulseaudio )
167 + rbd? ( sys-cluster/ceph )
168 + sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
169 + sdl? (
170 + media-libs/libsdl2[video]
171 + media-libs/libsdl2[static-libs(+)]
172 + )
173 + sdl-image? ( media-libs/sdl2-image[static-libs(+)] )
174 + seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
175 + slirp? ( net-libs/libslirp[static-libs(+)] )
176 + smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
177 + snappy? ( app-arch/snappy:= )
178 + spice? (
179 + >=app-emulation/spice-protocol-0.12.3
180 + >=app-emulation/spice-0.12.0[static-libs(+)]
181 + )
182 + ssh? ( >=net-libs/libssh-0.8.6[static-libs(+)] )
183 + udev? ( virtual/libudev[static-libs(+)] )
184 + usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
185 + usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
186 + vde? ( net-misc/vde[static-libs(+)] )
187 + virgl? ( media-libs/virglrenderer[static-libs(+)] )
188 + virtfs? ( sys-libs/libcap )
189 + xen? ( app-emulation/xen-tools:= )
190 + xfs? ( sys-fs/xfsprogs[static-libs(+)] )
191 + zstd? ( >=app-arch/zstd-1.4.0[static-libs(+)] )
192 +"
193 +
194 +X86_FIRMWARE_DEPEND="
195 + pin-upstream-blobs? (
196 + ~sys-firmware/edk2-ovmf-201905[binary]
197 + ~sys-firmware/ipxe-1.0.0_p20190728[binary,qemu]
198 + ~sys-firmware/seabios-1.12.0[binary,seavgabios]
199 + ~sys-firmware/sgabios-0.1_pre8[binary]
200 + )
201 + !pin-upstream-blobs? (
202 + sys-firmware/edk2-ovmf
203 + sys-firmware/ipxe[qemu]
204 + >=sys-firmware/seabios-1.10.2[seavgabios]
205 + sys-firmware/sgabios
206 + )"
207 +PPC_FIRMWARE_DEPEND="
208 + pin-upstream-blobs? (
209 + ~sys-firmware/seabios-1.12.0[binary,seavgabios]
210 + )
211 + !pin-upstream-blobs? (
212 + >=sys-firmware/seabios-1.10.2[seavgabios]
213 + )
214 +"
215 +
216 +BDEPEND="
217 + $(python_gen_impl_dep)
218 + dev-lang/perl
219 + sys-apps/texinfo
220 + virtual/pkgconfig
221 + doc? ( dev-python/sphinx )
222 + gtk? ( nls? ( sys-devel/gettext ) )
223 + test? (
224 + dev-libs/glib[utils]
225 + sys-devel/bc
226 + )
227 +"
228 +CDEPEND="
229 + !static? (
230 + ${ALL_DEPEND//\[static-libs(+)]}
231 + ${SOFTMMU_TOOLS_DEPEND//\[static-libs(+)]}
232 + )
233 + qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
234 + qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
235 + qemu_softmmu_targets_ppc? ( ${PPC_FIRMWARE_DEPEND} )
236 + qemu_softmmu_targets_ppc64? ( ${PPC_FIRMWARE_DEPEND} )
237 +"
238 +DEPEND="${CDEPEND}
239 + kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
240 + static? (
241 + ${ALL_DEPEND}
242 + ${SOFTMMU_TOOLS_DEPEND}
243 + )
244 + static-user? ( ${ALL_DEPEND} )"
245 +RDEPEND="${CDEPEND}
246 + acct-group/kvm
247 + selinux? ( sec-policy/selinux-qemu )"
248 +
249 +PATCHES=(
250 + "${FILESDIR}"/${PN}-2.11.1-capstone_include_path.patch
251 + "${FILESDIR}"/${PN}-5.2.0-cleaner-werror.patch
252 + "${FILESDIR}"/${PN}-5.2.0-disable-keymap.patch
253 + "${FILESDIR}"/${PN}-5.2.0-strings.patch
254 + "${FILESDIR}"/${PN}-5.2.0-fix-firmware-path.patch
255 + "${FILESDIR}"/${PN}-5.2.0-no-pie-ld.patch
256 +)
257 +
258 +QA_PREBUILT="
259 + usr/share/qemu/hppa-firmware.img
260 + usr/share/qemu/openbios-ppc
261 + usr/share/qemu/openbios-sparc64
262 + usr/share/qemu/openbios-sparc32
263 + usr/share/qemu/opensbi-riscv64-generic-fw_dynamic.elf
264 + usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.elf
265 + usr/share/qemu/palcode-clipper
266 + usr/share/qemu/s390-ccw.img
267 + usr/share/qemu/s390-netboot.img
268 + usr/share/qemu/u-boot.e500
269 +"
270 +
271 +QA_WX_LOAD="usr/bin/qemu-i386
272 + usr/bin/qemu-x86_64
273 + usr/bin/qemu-alpha
274 + usr/bin/qemu-arm
275 + usr/bin/qemu-cris
276 + usr/bin/qemu-m68k
277 + usr/bin/qemu-microblaze
278 + usr/bin/qemu-microblazeel
279 + usr/bin/qemu-mips
280 + usr/bin/qemu-mipsel
281 + usr/bin/qemu-or1k
282 + usr/bin/qemu-ppc
283 + usr/bin/qemu-ppc64
284 + usr/bin/qemu-ppc64abi32
285 + usr/bin/qemu-sh4
286 + usr/bin/qemu-sh4eb
287 + usr/bin/qemu-sparc
288 + usr/bin/qemu-sparc64
289 + usr/bin/qemu-armeb
290 + usr/bin/qemu-sparc32plus
291 + usr/bin/qemu-s390x
292 + usr/bin/qemu-unicore32
293 +"
294 +
295 +DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure you have the
296 +kernel module loaded before running kvm. The easiest way to ensure that the
297 +kernel module is loaded is to load it on boot.
298 + For AMD CPUs the module is called 'kvm-amd'.
299 + For Intel CPUs the module is called 'kvm-intel'.
300 +Please review /etc/conf.d/modules for how to load these.
301 +
302 +Make sure your user is in the 'kvm' group. Just run
303 + $ gpasswd -a <USER> kvm
304 +then have <USER> re-login.
305 +
306 +For brand new installs, the default permissions on /dev/kvm might not let
307 +you access it. You can tell udev to reset ownership/perms:
308 + $ udevadm trigger -c add /dev/kvm
309 +
310 +If you want to register binfmt handlers for qemu user targets:
311 +For openrc:
312 + # rc-update add qemu-binfmt
313 +For systemd:
314 + # ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf"
315 +
316 +pkg_pretend() {
317 + if use kernel_linux && kernel_is lt 2 6 25; then
318 + eerror "This version of KVM requires a host kernel of 2.6.25 or higher."
319 + elif use kernel_linux; then
320 + if ! linux_config_exists; then
321 + eerror "Unable to check your kernel for KVM support"
322 + else
323 + CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
324 + ERROR_KVM="You must enable KVM in your kernel to continue"
325 + ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
326 + ERROR_KVM_AMD+=" your kernel configuration."
327 + ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
328 + ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
329 + ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
330 + ERROR_TUN+=" into your kernel or loaded as a module to use the"
331 + ERROR_TUN+=" virtual network device if using -net tap."
332 + ERROR_BRIDGE="You will also need support for 802.1d"
333 + ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
334 + use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
335 + ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
336 + ERROR_VHOST_NET+=" support"
337 +
338 + if use amd64 || use x86 || use amd64-linux || use x86-linux; then
339 + if grep -q AuthenticAMD /proc/cpuinfo; then
340 + CONFIG_CHECK+=" ~KVM_AMD"
341 + elif grep -q GenuineIntel /proc/cpuinfo; then
342 + CONFIG_CHECK+=" ~KVM_INTEL"
343 + fi
344 + fi
345 +
346 + use python && CONFIG_CHECK+=" ~DEBUG_FS"
347 + ERROR_DEBUG_FS="debugFS support required for kvm_stat"
348 +
349 + # Now do the actual checks setup above
350 + check_extra_config
351 + fi
352 + fi
353 +
354 + if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
355 + eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
356 + eerror "instances are still pointing to it. Please update your"
357 + eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
358 + eerror "and the right system binary (e.g. qemu-system-x86_64)."
359 + die "update your virt configs to not use qemu-kvm"
360 + fi
361 +}
362 +
363 +# Sanity check to make sure target lists are kept up-to-date.
364 +check_targets() {
365 + local var=$1 mak=$2
366 + local detected sorted
367 +
368 + pushd "${S}"/default-configs/targets/ >/dev/null || die
369 +
370 + # Force C locale until glibc is updated. #564936
371 + detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
372 + sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
373 + if [[ ${sorted} != "${detected}" ]] ; then
374 + eerror "The ebuild needs to be kept in sync."
375 + eerror "${var}: ${sorted}"
376 + eerror "$(printf '%-*s' ${#var} configure): ${detected}"
377 + die "sync ${var} to the list of targets"
378 + fi
379 +
380 + popd >/dev/null
381 +}
382 +
383 +src_prepare() {
384 + # workaround -fcommon breakage: bug #726560
385 + [[ ${PV} == 5.2.0 ]] || die "Check if -fcommon hack is needed"
386 + filter-flags -fcommon
387 +
388 + check_targets IUSE_SOFTMMU_TARGETS softmmu
389 + check_targets IUSE_USER_TARGETS linux-user
390 +
391 + default
392 +
393 + # Use correct toolchain to fix cross-compiling
394 + tc-export AR AS LD NM OBJCOPY PKG_CONFIG RANLIB STRINGS
395 + export WINDRES=${CHOST}-windres
396 +
397 + # Verbose builds
398 + MAKEOPTS+=" V=1"
399 +
400 + # Remove bundled copy of libfdt
401 + rm -r dtc || die
402 +
403 + # conditionally apply patches for musl support
404 + if use elibc_musl ; then
405 + eapply "${FILESDIR}"/musl-patches/0001-linux-user-fix-build-with-musl-on-aarch64.patch
406 + eapply "${FILESDIR}"/musl-patches/0001-linux-user-fix-build-with-musl-on-ppc64le.patch
407 + eapply "${FILESDIR}"/musl-patches/0001-virtio-host-input-use-safe-64-bit-time-accessors-for.patch
408 + eapply "${FILESDIR}"/musl-patches/0002-virtio-user-input-use-safe-64-bit-time-accessors-for.patch
409 + eapply "${FILESDIR}"/musl-patches/0006-linux-user-signal.c-define-__SIGRTMIN-MAX-for-non-GN.patch
410 + eapply "${FILESDIR}"/musl-patches/MAP_SYNC-fix.patch
411 + eapply "${FILESDIR}"/musl-patches/fix-segevent-and-sigval_t.patch
412 + eapply "${FILESDIR}"/musl-patches/fix-sendmsg.patch
413 + eapply "${FILESDIR}"/musl-patches/fix-sockios-header.patch
414 + eapply "${FILESDIR}"/musl-patches/guest-agent-shutdown.patch
415 + eapply "${FILESDIR}"/musl-patches/ignore-signals-33-and-64-to-allow-golang-emulation.patch
416 + eapply "${FILESDIR}"/musl-patches/mips-softfloat.patch
417 + eapply "${FILESDIR}"/musl-patches/musl-F_SHLCK-and-F_EXLCK.patch
418 + eapply "${FILESDIR}"/musl-patches/xattr_size_max.patch
419 + fi
420 +}
421 +
422 +##
423 +# configures qemu based on the build directory and the build type
424 +# we are using.
425 +#
426 +qemu_src_configure() {
427 + debug-print-function ${FUNCNAME} "$@"
428 +
429 + local buildtype=$1
430 + local builddir="${S}/${buildtype}-build"
431 +
432 + mkdir "${builddir}"
433 +
434 + local conf_opts=(
435 + --prefix=/usr
436 + --sysconfdir=/etc
437 + --bindir=/usr/bin
438 + --libdir=/usr/$(get_libdir)
439 + --datadir=/usr/share
440 + --docdir=/usr/share/doc/${PF}/html
441 + --mandir=/usr/share/man
442 + --localstatedir=/var
443 + --disable-bsd-user
444 + --disable-containers # bug #732972
445 + --disable-guest-agent
446 + --disable-strip
447 +
448 + # bug #746752: TCG interpreter has a few limitations:
449 + # - it does not support FPU
450 + # - it's generally slower on non-self-modifying code
451 + # It's advantage is support for host architectures
452 + # where native codegeneration is not implemented.
453 + # Gentoo has qemu keyworded only on targets with
454 + # native code generation available. Avoid the interpreter.
455 + --disable-tcg-interpreter
456 +
457 + --disable-werror
458 + # We support gnutls/nettle for crypto operations. It is possible
459 + # to use gcrypt when gnutls/nettle are disabled (but not when they
460 + # are enabled), but it's not really worth the hassle. Disable it
461 + # all the time to avoid automatically detecting it. #568856
462 + --disable-gcrypt
463 + --python="${PYTHON}"
464 + --cc="$(tc-getCC)"
465 + --cxx="$(tc-getCXX)"
466 + --host-cc="$(tc-getBUILD_CC)"
467 + $(use_enable debug debug-info)
468 + $(use_enable debug debug-tcg)
469 + $(use_enable doc docs)
470 + $(use_enable nls gettext)
471 + $(use_enable plugins)
472 + $(use_enable xattr attr)
473 + )
474 +
475 + # Disable options not used by user targets. This simplifies building
476 + # static user targets (USE=static-user) considerably.
477 + conf_notuser() {
478 + if [[ ${buildtype} == "user" ]] ; then
479 + echo "--disable-${2:-$1}"
480 + else
481 + use_enable "$@"
482 + fi
483 + }
484 + # Enable option only for softmmu build, but not 'user' or 'tools'
485 + conf_softmmu() {
486 + if [[ ${buildtype} == "softmmu" ]] ; then
487 + use_enable "$@"
488 + else
489 + echo "--disable-${2:-$1}"
490 + fi
491 + }
492 + # Enable option only for tools build, but not 'user' or 'softmmu'
493 + conf_tools() {
494 + if [[ ${buildtype} == "tools" ]] ; then
495 + use_enable "$@"
496 + else
497 + echo "--disable-${2:-$1}"
498 + fi
499 + }
500 + conf_opts+=(
501 + $(conf_notuser accessibility brlapi)
502 + $(conf_notuser aio linux-aio)
503 + $(conf_notuser bzip2)
504 + $(conf_notuser capstone)
505 + $(conf_notuser caps cap-ng)
506 + $(conf_notuser curl)
507 + $(conf_notuser fdt)
508 + $(conf_notuser glusterfs)
509 + $(conf_notuser gnutls)
510 + $(conf_notuser gnutls nettle)
511 + $(conf_notuser gtk)
512 + $(conf_notuser infiniband rdma)
513 + $(conf_notuser iscsi libiscsi)
514 + $(conf_notuser io-uring linux-io-uring)
515 + $(conf_notuser jemalloc jemalloc)
516 + $(conf_notuser jpeg vnc-jpeg)
517 + $(conf_notuser kernel_linux kvm)
518 + $(conf_notuser lzo)
519 + $(conf_notuser multipath mpath)
520 + $(conf_notuser ncurses curses)
521 + $(conf_notuser nfs libnfs)
522 + $(conf_notuser numa)
523 + $(conf_notuser opengl)
524 + $(conf_notuser png vnc-png)
525 + $(conf_notuser rbd)
526 + $(conf_notuser sasl vnc-sasl)
527 + $(conf_notuser sdl)
528 + $(conf_softmmu sdl-image)
529 + $(conf_notuser seccomp)
530 + $(conf_notuser slirp slirp system)
531 + $(conf_notuser smartcard)
532 + $(conf_notuser snappy)
533 + $(conf_notuser spice)
534 + $(conf_notuser ssh libssh)
535 + $(conf_notuser udev libudev)
536 + $(conf_notuser usb libusb)
537 + $(conf_notuser usbredir usb-redir)
538 + $(conf_notuser vde)
539 + $(conf_notuser vhost-net)
540 + $(conf_notuser vhost-user-fs)
541 + $(conf_tools vhost-user-fs virtiofsd)
542 + $(conf_notuser virgl virglrenderer)
543 + $(conf_notuser virtfs)
544 + $(conf_notuser vnc)
545 + $(conf_notuser vte)
546 + $(conf_notuser xen)
547 + $(conf_notuser xen xen-pci-passthrough)
548 + $(conf_notuser xfs xfsctl)
549 + # use prebuilt keymaps, bug #759604
550 + --disable-xkbcommon
551 + $(conf_notuser zstd)
552 + )
553 +
554 + if [[ ${buildtype} == "user" ]] ; then
555 + conf_opts+=( --disable-libxml2 )
556 + else
557 + conf_opts+=( --enable-libxml2 )
558 + fi
559 +
560 + if [[ ! ${buildtype} == "user" ]] ; then
561 + # audio options
562 + local audio_opts=(
563 + # Note: backend order matters here: #716202
564 + # We iterate from higher-level to lower level.
565 + $(usex pulseaudio pa "")
566 + $(usev jack)
567 + $(usev sdl)
568 + $(usev alsa)
569 + $(usev oss)
570 + )
571 + conf_opts+=(
572 + --audio-drv-list=$(printf "%s," "${audio_opts[@]}")
573 + )
574 + fi
575 +
576 + case ${buildtype} in
577 + user)
578 + conf_opts+=(
579 + --enable-linux-user
580 + --disable-system
581 + --disable-blobs
582 + --disable-tools
583 + )
584 + local static_flag="static-user"
585 + ;;
586 + softmmu)
587 + conf_opts+=(
588 + --disable-linux-user
589 + --enable-system
590 + --disable-tools
591 + )
592 + local static_flag="static"
593 + ;;
594 + tools)
595 + conf_opts+=(
596 + --disable-linux-user
597 + --disable-system
598 + --disable-blobs
599 + --enable-tools
600 + )
601 + local static_flag="static"
602 + ;;
603 + esac
604 +
605 + local targets="${buildtype}_targets"
606 + [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
607 +
608 + # Add support for SystemTAP
609 + use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
610 +
611 + # We always want to attempt to build with PIE support as it results
612 + # in a more secure binary. But it doesn't work with static or if
613 + # the current GCC doesn't have PIE support.
614 + if use ${static_flag}; then
615 + conf_opts+=( --static --disable-pie )
616 + else
617 + tc-enables-pie && conf_opts+=( --enable-pie )
618 + fi
619 +
620 + # Meson will not use a cross-file unless cross_prefix is set.
621 + tc-is-cross-compiler && conf_opts+=( --cross-prefix="${CHOST}-" )
622 +
623 + # Plumb through equivalent of EXTRA_ECONF to allow experiments
624 + # like bug #747928.
625 + conf_opts+=( ${EXTRA_CONF_QEMU} )
626 +
627 + echo "../configure ${conf_opts[*]}"
628 + cd "${builddir}"
629 + ../configure "${conf_opts[@]}" || die "configure failed"
630 +
631 + # FreeBSD's kernel does not support QEMU assigning/grabbing
632 + # host USB devices yet
633 + use kernel_FreeBSD && \
634 + sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
635 +}
636 +
637 +src_configure() {
638 + local target
639 +
640 + python_setup
641 +
642 + softmmu_targets= softmmu_bins=()
643 + user_targets= user_bins=()
644 +
645 + for target in ${IUSE_SOFTMMU_TARGETS} ; do
646 + if use "qemu_softmmu_targets_${target}"; then
647 + softmmu_targets+=",${target}-softmmu"
648 + softmmu_bins+=( "qemu-system-${target}" )
649 + fi
650 + done
651 +
652 + for target in ${IUSE_USER_TARGETS} ; do
653 + if use "qemu_user_targets_${target}"; then
654 + user_targets+=",${target}-linux-user"
655 + user_bins+=( "qemu-${target}" )
656 + fi
657 + done
658 +
659 + softmmu_targets=${softmmu_targets#,}
660 + user_targets=${user_targets#,}
661 +
662 + [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
663 + [[ -n ${user_targets} ]] && qemu_src_configure "user"
664 + qemu_src_configure "tools"
665 +}
666 +
667 +src_compile() {
668 + if [[ -n ${user_targets} ]]; then
669 + cd "${S}/user-build"
670 + default
671 + fi
672 +
673 + if [[ -n ${softmmu_targets} ]]; then
674 + cd "${S}/softmmu-build"
675 + default
676 + fi
677 +
678 + cd "${S}/tools-build"
679 + default
680 +}
681 +
682 +src_test() {
683 + if [[ -n ${softmmu_targets} ]]; then
684 + cd "${S}/softmmu-build"
685 + pax-mark m */qemu-system-* #515550
686 + emake check
687 + fi
688 +}
689 +
690 +qemu_python_install() {
691 + python_domodule "${S}/python/qemu"
692 +
693 + python_doscript "${S}/scripts/kvm/vmxcap"
694 + python_doscript "${S}/scripts/qmp/qmp-shell"
695 + python_doscript "${S}/scripts/qmp/qemu-ga-client"
696 +}
697 +
698 +# Generate binfmt support files.
699 +# - /etc/init.d/qemu-binfmt script which registers the user handlers (openrc)
700 +# - /usr/share/qemu/binfmt.d/qemu.conf (for use with systemd-binfmt)
701 +generate_initd() {
702 + local out="${T}/qemu-binfmt"
703 + local out_systemd="${T}/qemu.conf"
704 + local d="${T}/binfmt.d"
705 +
706 + einfo "Generating qemu binfmt scripts and configuration files"
707 +
708 + # Generate the debian fragments first.
709 + mkdir -p "${d}"
710 + "${S}"/scripts/qemu-binfmt-conf.sh \
711 + --debian \
712 + --exportdir "${d}" \
713 + --qemu-path "${EPREFIX}/usr/bin" \
714 + || die
715 + # Then turn the fragments into a shell script we can source.
716 + sed -E -i \
717 + -e 's:^([^ ]+) (.*)$:\1="\2":' \
718 + "${d}"/* || die
719 +
720 + # Generate the init.d script by assembling the fragments from above.
721 + local f qcpu package interpreter magic mask
722 + cat "${FILESDIR}"/qemu-binfmt.initd.head >"${out}" || die
723 + for f in "${d}"/qemu-* ; do
724 + source "${f}"
725 +
726 + # Normalize the cpu logic like we do in the init.d for the native cpu.
727 + qcpu=${package#qemu-}
728 + case ${qcpu} in
729 + arm*) qcpu="arm";;
730 + mips*) qcpu="mips";;
731 + ppc*) qcpu="ppc";;
732 + s390*) qcpu="s390";;
733 + sh*) qcpu="sh";;
734 + sparc*) qcpu="sparc";;
735 + esac
736 +
737 + # we use 'printf' here to be portable across 'sh'
738 + # implementations: #679168
739 + cat <<EOF >>"${out}"
740 + if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then
741 + printf '%s\n' ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register
742 + fi
743 +EOF
744 +
745 + echo ":${package}:M::${magic}:${mask}:${interpreter}:OC" >>"${out_systemd}"
746 +
747 + done
748 + cat "${FILESDIR}"/qemu-binfmt.initd.tail >>"${out}" || die
749 +}
750 +
751 +src_install() {
752 + if [[ -n ${user_targets} ]]; then
753 + cd "${S}/user-build"
754 + emake DESTDIR="${ED}" install
755 +
756 + # Install binfmt handler init script for user targets.
757 + generate_initd
758 + doinitd "${T}/qemu-binfmt"
759 +
760 + # Install binfmt/qemu.conf.
761 + insinto "/usr/share/qemu/binfmt.d"
762 + doins "${T}/qemu.conf"
763 + fi
764 +
765 + if [[ -n ${softmmu_targets} ]]; then
766 + cd "${S}/softmmu-build"
767 + emake DESTDIR="${ED}" install
768 +
769 + # This might not exist if the test failed. #512010
770 + [[ -e check-report.html ]] && dodoc check-report.html
771 +
772 + if use kernel_linux; then
773 + udev_newrules "${FILESDIR}"/65-kvm.rules-r2 65-kvm.rules
774 + fi
775 +
776 + if use python; then
777 + python_foreach_impl qemu_python_install
778 + fi
779 + fi
780 +
781 + cd "${S}/tools-build"
782 + emake DESTDIR="${ED}" install
783 +
784 + # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
785 + pushd "${ED}"/usr/bin >/dev/null
786 + pax-mark mr "${softmmu_bins[@]}" "${user_bins[@]}" # bug 575594
787 + popd >/dev/null
788 +
789 + # Install config file example for qemu-bridge-helper
790 + insinto "/etc/qemu"
791 + doins "${FILESDIR}/bridge.conf"
792 +
793 + cd "${S}"
794 + dodoc MAINTAINERS docs/specs/pci-ids.txt
795 + newdoc pc-bios/README README.pc-bios
796 +
797 + # Disallow stripping of prebuilt firmware files.
798 + dostrip -x ${QA_PREBUILT}
799 +
800 + if [[ -n ${softmmu_targets} ]]; then
801 + # Remove SeaBIOS since we're using the SeaBIOS packaged one
802 + rm "${ED}/usr/share/qemu/bios.bin"
803 + rm "${ED}/usr/share/qemu/bios-256k.bin"
804 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
805 + dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
806 + dosym ../seabios/bios-256k.bin /usr/share/qemu/bios-256k.bin
807 + fi
808 +
809 + # Remove vgabios since we're using the seavgabios packaged one
810 + rm "${ED}/usr/share/qemu/vgabios.bin"
811 + rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
812 + rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
813 + rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
814 + rm "${ED}/usr/share/qemu/vgabios-virtio.bin"
815 + rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
816 + # PPC/PPC64 loads vgabios-stdvga
817 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 || use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64; then
818 + dosym ../seavgabios/vgabios-isavga.bin /usr/share/qemu/vgabios.bin
819 + dosym ../seavgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
820 + dosym ../seavgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
821 + dosym ../seavgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
822 + dosym ../seavgabios/vgabios-virtio.bin /usr/share/qemu/vgabios-virtio.bin
823 + dosym ../seavgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
824 + fi
825 +
826 + # Remove sgabios since we're using the sgabios packaged one
827 + rm "${ED}/usr/share/qemu/sgabios.bin"
828 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
829 + dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
830 + fi
831 +
832 + # Remove iPXE since we're using the iPXE packaged one
833 + rm "${ED}"/usr/share/qemu/pxe-*.rom
834 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
835 + dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
836 + dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
837 + dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
838 + dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
839 + dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
840 + dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
841 + fi
842 + fi
843 +
844 + DISABLE_AUTOFORMATTING=true
845 + readme.gentoo_create_doc
846 +}
847 +
848 +firmware_abi_change() {
849 + local pv
850 + for pv in ${REPLACING_VERSIONS}; do
851 + if ver_test ${pv} -lt ${FIRMWARE_ABI_VERSION}; then
852 + return 0
853 + fi
854 + done
855 + return 1
856 +}
857 +
858 +pkg_postinst() {
859 + if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
860 + udev_reload
861 + fi
862 +
863 + xdg_icon_cache_update
864 +
865 + [[ -z ${EPREFIX} ]] && [[ -f ${EROOT}/usr/libexec/qemu-bridge-helper ]] && \
866 + fcaps cap_net_admin ${EROOT}/usr/libexec/qemu-bridge-helper
867 +
868 + DISABLE_AUTOFORMATTING=true
869 + readme.gentoo_print_elog
870 +
871 + if use pin-upstream-blobs && firmware_abi_change; then
872 + ewarn "This version of qemu pins new versions of firmware blobs:"
873 + ewarn " $(best_version sys-firmware/edk2-ovmf)"
874 + ewarn " $(best_version sys-firmware/ipxe)"
875 + ewarn " $(best_version sys-firmware/seabios)"
876 + ewarn " $(best_version sys-firmware/sgabios)"
877 + ewarn "This might break resume of hibernated guests (started with a different"
878 + ewarn "firmware version) and live migration to/from qemu versions with different"
879 + ewarn "firmware. Please (cold) restart all running guests. For functional"
880 + ewarn "guest migration ensure that all"
881 + ewarn "hosts run at least"
882 + ewarn " app-emulation/qemu-${FIRMWARE_ABI_VERSION}."
883 + fi
884 +}
885 +
886 +pkg_info() {
887 + echo "Using:"
888 + echo " $(best_version app-emulation/spice-protocol)"
889 + echo " $(best_version sys-firmware/edk2-ovmf)"
890 + if has_version 'sys-firmware/edk2-ovmf[binary]'; then
891 + echo " USE=binary"
892 + else
893 + echo " USE=''"
894 + fi
895 + echo " $(best_version sys-firmware/ipxe)"
896 + echo " $(best_version sys-firmware/seabios)"
897 + if has_version 'sys-firmware/seabios[binary]'; then
898 + echo " USE=binary"
899 + else
900 + echo " USE=''"
901 + fi
902 + echo " $(best_version sys-firmware/sgabios)"
903 +}
904 +
905 +pkg_postrm() {
906 + xdg_icon_cache_update
907 +}