### this file is sourced not run
PKGVER=6.0.0
PKGBUILD=1
PKGARCH=x86_64

# source: james
TARBALL=qemu-$PKGVER.tar.xz
MD5SUM=cce185dc0119546e395909e8a71a75bb
SRC_URL=https://download.qemu.org/$TARBALL
BUNDLE=

SLACKREQ='libncurses libSDL2 libSDL2-image libusb libssh2 curl bluez libvte 
libaio libattr libiscsi'  # lzo2, libcap-ng, libusbredir build-time only
SLACKDESC="qemu-arm-x86_64: qemu-arm-x86_64 $PKGVER (QEMU for arm/x86_64)  
qemu-arm-x86_64:  
qemu-arm-x86_64: QEMU is a generic and open source machine emulator and 
qemu-arm-x86_64: virtualizer. This package provides emulation for:
qemu-arm-x86_64: - ARM (system and linux)
qemu-arm-x86_64: - ARM64 (system and linux)
qemu-arm-x86_64: - x86_64 (system only)
qemu-arm-x86_64: 
qemu-arm-x86_64: 
qemu-arm-x86_64: 
qemu-arm-x86_64:
"

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/qemu* &&

	# upstream patches	
	true
}

### package
pkg_package() {
	cp tmp/pkg/uefi-bios.bin usr/share/qemu &&
	# over-write broken files with local copy, if any
	true
}

### build
pkg_build() {
	cd /tmp/qemu* &&	
	unset CFLAGS CXXFLAGS && # build with default CFLAGS, not -Os
	./configure $CONFFLAGS \
		--target-list="arm-softmmu arm-linux-user aarch64-softmmu aarch64-linux-user x86_64-softmmu" \
		--audio-drv-list="alsa sdl"  \
		--enable-sdl --enable-sdl-image &&
	make $MAKEFLAGS && make install &&

	# BLFS says this should suid
	chmod 4750 /usr/libexec/qemu-bridge-helper &&

	# note: in qemu 4.2 onwards, the std docs needs python-sphinx to build
	# we don't have python-sphinx yet, so steal the PDF doc from
	# https://qemu.readthedocs.io/_/downloads/en/stable/pdf/
	# unfortunately qemu website only produces the latest docs, 
	# so if we're building any older release, we're SOL.
	install -dm755 /usr/share/doc/qemu-$PKGVER &&
	install /tmp/pkg/docs/* /usr/share/doc/qemu-$PKGVER
	
	# extra docs
	cp -a docs /usr/share/doc/qemu-$PKGVER &&
	chown -R 0:0 /usr/share/doc/qemu-$PKGVER/docs &&

	# copy useful scripts
	install -m755 scripts/qemu-binfmt-conf.sh /usr/bin &&

	pkg_build_slackdesc 
}
