Gentoo Archives: gentoo-commits

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