1SUMMARY = "Fast open source processor emulator"
2DESCRIPTION = "QEMU is a hosted virtual machine monitor: it emulates the \
3machine's processor through dynamic binary translation and provides a set \
4of different hardware and device models for the machine, enabling it to run \
5a variety of guest operating systems"
6HOMEPAGE = "http://qemu.org"
7LICENSE = "GPL-2.0-only & LGPL-2.1-only"
8
9RDEPENDS:${PN}-ptest = "bash"
10
11require qemu-targets.inc
12inherit pkgconfig ptest
13
14LIC_FILES_CHKSUM = "file://COPYING;md5=441c28d2cf86e15a37fa47e15a72fbac \
15                    file://COPYING.LIB;endline=24;md5=8c5efda6cf1e1b03dcfd0e6c0d271c7f"
16
17SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
18           file://powerpc_rom.bin \
19           file://run-ptest \
20           file://0001-qemu-Add-addition-environment-space-to-boot-loader-q.patch \
21           file://0002-chardev-connect-socket-to-a-spawned-command.patch \
22           file://0003-apic-fixup-fallthrough-to-PIC.patch \
23           file://0004-configure-Add-pkg-config-handling-for-libgcrypt.patch \
24           file://0005-qemu-Do-not-include-file-if-not-exists.patch \
25           file://0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch \
26           file://0007-qemu-Determinism-fixes.patch \
27           file://0008-tests-meson.build-use-relative-path-to-refer-to-file.patch \
28           file://0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch \
29           file://0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch \
30           "
31UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar"
32
33SRC_URI[sha256sum] = "f6b375c7951f728402798b0baabb2d86478ca53d44cedbefabbe1c46bf46f839"
34
35SRC_URI:append:class-target = " file://cross.patch"
36SRC_URI:append:class-nativesdk = " file://cross.patch"
37
38# Applies against virglrender < 0.6.0 and not qemu itself
39CVE_CHECK_IGNORE += "CVE-2017-5957"
40
41# The VNC server can expose host files uder some circumstances. We don't
42# enable it by default.
43CVE_CHECK_IGNORE += "CVE-2007-0998"
44
45# 'The issues identified by this CVE were determined to not constitute a vulnerability.'
46# https://bugzilla.redhat.com/show_bug.cgi?id=1609015#c11
47CVE_CHECK_IGNORE += "CVE-2018-18438"
48
49COMPATIBLE_HOST:mipsarchn32 = "null"
50COMPATIBLE_HOST:mipsarchn64 = "null"
51COMPATIBLE_HOST:riscv32 = "null"
52
53# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
54# upstream states qemu doesn't work without optimization
55DEBUG_BUILD = "0"
56
57do_install:append() {
58    # Prevent QA warnings about installed ${localstatedir}/run
59    if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi
60}
61
62do_install_ptest() {
63	cp -rL ${B}/tests ${D}${PTEST_PATH}
64	find ${D}${PTEST_PATH}/tests -type f -name "*.[Sshcodp]" | xargs -i rm -rf {}
65
66	# Don't check the file genreated by configure
67	sed -i -e "1s,#!/usr/bin/bash,#!${base_bindir}/bash," ${D}${PTEST_PATH}/tests/data/acpi/disassemle-aml.sh
68
69	# Strip the paths from the QEMU variable, we can use PATH
70	sed -i -e "s#^QEMU=.*/qemu-#QEMU=qemu-#g" ${D}${PTEST_PATH}/tests/tcg/*.mak
71
72        # Strip compiler flags as they break reproducibility
73        sed -i -e "s,CROSS_CC_GUEST=.*,CROSS_CC_GUEST=," ${D}${PTEST_PATH}/tests/tcg/*.mak
74}
75
76# QEMU_TARGETS is overridable variable
77QEMU_TARGETS ?= "arm aarch64 i386 mips mipsel mips64 mips64el ppc ppc64 ppc64le riscv32 riscv64 sh4 x86_64"
78
79EXTRA_OECONF = " \
80    --prefix=${prefix} \
81    --bindir=${bindir} \
82    --includedir=${includedir} \
83    --libdir=${libdir} \
84    --mandir=${mandir} \
85    --datadir=${datadir} \
86    --docdir=${docdir}/${BPN} \
87    --sysconfdir=${sysconfdir} \
88    --libexecdir=${libexecdir} \
89    --localstatedir=${localstatedir} \
90    --with-suffix=${BPN} \
91    --disable-strip \
92    --disable-werror \
93    --extra-cflags='${CFLAGS}' \
94    --extra-ldflags='${LDFLAGS}' \
95    --with-git=/bin/false \
96    --with-git-submodules=ignore \
97    --meson=meson \
98    ${PACKAGECONFIG_CONFARGS} \
99    "
100
101B = "${WORKDIR}/build"
102
103#EXTRA_OECONF:append = " --python=${HOSTTOOLS_DIR}/python3"
104
105do_configure:prepend:class-native() {
106	# Append build host pkg-config paths for native target since the host may provide sdl
107	BHOST_PKGCONFIG_PATH=$(PATH=/usr/bin:/bin pkg-config --variable pc_path pkg-config || echo "")
108	if [ ! -z "$BHOST_PKGCONFIG_PATH" ]; then
109		export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$BHOST_PKGCONFIG_PATH
110	fi
111}
112
113do_configure() {
114    ${S}/configure ${EXTRA_OECONF}
115}
116do_configure[cleandirs] += "${B}"
117
118do_install () {
119	export STRIP=""
120	oe_runmake 'DESTDIR=${D}' install
121}
122
123# The following fragment will create a wrapper for qemu-mips user emulation
124# binary in order to work around a segmentation fault issue. Basically, by
125# default, the reserved virtual address space for 32-on-64 bit is set to 4GB.
126# This will trigger a MMU access fault in the virtual CPU. With this change,
127# the qemu-mips works fine.
128# IMPORTANT: This piece needs to be removed once the root cause is fixed!
129do_install:append() {
130	if [ -e "${D}/${bindir}/qemu-mips" ]; then
131		create_wrapper ${D}/${bindir}/qemu-mips \
132			QEMU_RESERVED_VA=0x0
133	fi
134}
135# END of qemu-mips workaround
136
137# Disable kvm/virgl/mesa on targets that do not support it
138PACKAGECONFIG:remove:darwin = "kvm virglrenderer epoxy gtk+"
139PACKAGECONFIG:remove:mingw32 = "kvm virglrenderer epoxy gtk+"
140
141PACKAGECONFIG[sdl] = "--enable-sdl,--disable-sdl,libsdl2"
142PACKAGECONFIG[virtfs] = "--enable-virtfs --enable-attr --enable-cap-ng,--disable-virtfs,libcap-ng attr,"
143PACKAGECONFIG[aio] = "--enable-linux-aio,--disable-linux-aio,libaio,"
144PACKAGECONFIG[xen] = "--enable-xen,--disable-xen,xen-tools,xen-tools-libxenstore xen-tools-libxenctrl xen-tools-libxenguest"
145PACKAGECONFIG[vnc-sasl] = "--enable-vnc --enable-vnc-sasl,--disable-vnc-sasl,cyrus-sasl,"
146PACKAGECONFIG[vnc-jpeg] = "--enable-vnc --enable-vnc-jpeg,--disable-vnc-jpeg,jpeg,"
147PACKAGECONFIG[vnc-png] = "--enable-vnc --enable-vnc-png,--disable-vnc-png,libpng,"
148PACKAGECONFIG[libcurl] = "--enable-curl,--disable-curl,curl,"
149PACKAGECONFIG[nss] = "--enable-smartcard,--disable-smartcard,nss,"
150PACKAGECONFIG[curses] = "--enable-curses,--disable-curses,ncurses,"
151PACKAGECONFIG[gtk+] = "--enable-gtk,--disable-gtk,gtk+3 gettext-native"
152PACKAGECONFIG[vte] = "--enable-vte,--disable-vte,vte gettext-native"
153PACKAGECONFIG[libcap-ng] = "--enable-cap-ng,--disable-cap-ng,libcap-ng,"
154PACKAGECONFIG[ssh] = "--enable-libssh,--disable-libssh,libssh,"
155PACKAGECONFIG[gcrypt] = "--enable-gcrypt,--disable-gcrypt,libgcrypt,"
156PACKAGECONFIG[nettle] = "--enable-nettle,--disable-nettle,nettle"
157PACKAGECONFIG[libusb] = "--enable-libusb,--disable-libusb,libusb1"
158PACKAGECONFIG[fdt] = "--enable-fdt,--disable-fdt,dtc"
159PACKAGECONFIG[alsa] = "--audio-drv-list=default,,alsa-lib"
160PACKAGECONFIG[epoxy] = "--enable-opengl,--disable-opengl,libepoxy"
161PACKAGECONFIG[lzo] = "--enable-lzo,--disable-lzo,lzo"
162PACKAGECONFIG[numa] = "--enable-numa,--disable-numa,numactl"
163PACKAGECONFIG[gnutls] = "--enable-gnutls,--disable-gnutls,gnutls"
164PACKAGECONFIG[bzip2] = "--enable-bzip2,--disable-bzip2,bzip2"
165PACKAGECONFIG[libiscsi] = "--enable-libiscsi,--disable-libiscsi"
166PACKAGECONFIG[kvm] = "--enable-kvm,--disable-kvm"
167PACKAGECONFIG[virglrenderer] = "--enable-virglrenderer,--disable-virglrenderer,virglrenderer"
168# spice will be in meta-networking layer
169PACKAGECONFIG[spice] = "--enable-spice,--disable-spice,spice"
170# usbredir will be in meta-networking layer
171PACKAGECONFIG[usb-redir] = "--enable-usb-redir,--disable-usb-redir,usbredir"
172PACKAGECONFIG[snappy] = "--enable-snappy,--disable-snappy,snappy"
173PACKAGECONFIG[glusterfs] = "--enable-glusterfs,--disable-glusterfs,glusterfs"
174PACKAGECONFIG[xkbcommon] = "--enable-xkbcommon,--disable-xkbcommon,libxkbcommon"
175PACKAGECONFIG[libudev] = "--enable-libudev,--disable-libudev,eudev"
176PACKAGECONFIG[attr] = "--enable-attr,--disable-attr,attr,"
177PACKAGECONFIG[rbd] = "--enable-rbd,--disable-rbd,ceph,ceph"
178PACKAGECONFIG[vhost] = "--enable-vhost-net,--disable-vhost-net,,"
179PACKAGECONFIG[ust] = "--enable-trace-backend=ust,--enable-trace-backend=nop,lttng-ust,"
180PACKAGECONFIG[pie] = "--enable-pie,--disable-pie,,"
181PACKAGECONFIG[seccomp] = "--enable-seccomp,--disable-seccomp,libseccomp"
182# libnfs is currently provided by meta-kodi
183PACKAGECONFIG[libnfs] = "--enable-libnfs,--disable-libnfs,libnfs"
184PACKAGECONFIG[pmem] = "--enable-libpmem,--disable-libpmem,pmdk"
185PACKAGECONFIG[pulsedio] = "--enable-pa,--disable-pa,pulseaudio"
186PACKAGECONFIG[selinux] = "--enable-selinux,--disable-selinux"
187PACKAGECONFIG[bpf] = "--enable-bpf,--disable-bpf,libbpf"
188
189INSANE_SKIP:${PN} = "arch"
190
191FILES:${PN} += "${datadir}/icons"
192