SUMMARY="A generic and open source machine emulator and virtualizer"
DESCRIPTION="QEMU is a generic and open source machine emulator and virtualizer.

QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a \
different machine (e.g. your own PC). By using dynamic translation, it \
achieves very good performance."
HOMEPAGE="http://wiki.qemu.org/"
COPYRIGHT="2003-2017 Fabrice Bellard"
LICENSE="GNU GPL v2"
REVISION="5"
SOURCE_URI="https://github.com/qemu/qemu/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="4f80eb491db11edff6d66355bf35929a87d811b4b6a2dad97ac9fd1d5f797519"
SOURCE_DIR="qemu-$portVersion"
PATCHES="qemu-$portVersion.patchset"

ARCHITECTURES="?all !x86_gcc2"
SECONDARY_ARCHITECTURES="?x86"

PROVIDES="
	qemu$secondaryArchSuffix = $portVersion
	cmd:qemu$secondaryArchSuffix = $portVersion
	cmd:qemu_img$secondaryArchSuffix = $portVersion
	cmd:qemu_io$secondaryArchSuffix = $portVersion
	cmd:qemu_system_aarch64$secondaryArchSuffix = $portVersion
	cmd:qemu_system_alpha$secondaryArchSuffix = $portVersion
	cmd:qemu_system_arm$secondaryArchSuffix = $portVersion
	cmd:qemu_system_cris$secondaryArchSuffix = $portVersion
	cmd:qemu_system_i386$secondaryArchSuffix = $portVersion
	cmd:qemu_system_lm32$secondaryArchSuffix = $portVersion
	cmd:qemu_system_m68k$secondaryArchSuffix = $portVersion
	cmd:qemu_system_microblaze$secondaryArchSuffix = $portVersion
	cmd:qemu_system_microblazeel$secondaryArchSuffix = $portVersion
	cmd:qemu_system_mips$secondaryArchSuffix = $portVersion
	cmd:qemu_system_mips64$secondaryArchSuffix = $portVersion
	cmd:qemu_system_mips64el$secondaryArchSuffix = $portVersion
	cmd:qemu_system_mipsel$secondaryArchSuffix = $portVersion
	cmd:qemu_system_moxie$secondaryArchSuffix = $portVersion
	cmd:qemu_system_or32$secondaryArchSuffix = $portVersion
	cmd:qemu_system_ppc$secondaryArchSuffix = $portVersion
	cmd:qemu_system_ppc64$secondaryArchSuffix = $portVersion
	cmd:qemu_system_ppcemb$secondaryArchSuffix = $portVersion
	cmd:qemu_system_s390x$secondaryArchSuffix = $portVersion
	cmd:qemu_system_sh4$secondaryArchSuffix = $portVersion
	cmd:qemu_system_sh4eb$secondaryArchSuffix = $portVersion
	cmd:qemu_system_sparc$secondaryArchSuffix = $portVersion
	cmd:qemu_system_sparc64$secondaryArchSuffix = $portVersion
	cmd:qemu_system_unicore32$secondaryArchSuffix = $portVersion
	cmd:qemu_system_x86_64$secondaryArchSuffix = $portVersion
	cmd:qemu_system_xtensa$secondaryArchSuffix = $portVersion
	cmd:qemu_system_xtensaeb$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libcurl$secondaryArchSuffix
	lib:libfdt$secondaryArchSuffix
	#lib:libgcrypt$secondaryArchSuffix
	lib:libGL$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgnutls$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblzo2$secondaryArchSuffix
	lib:libncursesw$secondaryArchSuffix
	lib:libnettle$secondaryArchSuffix
	lib:libpixman_1$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libsdl2_2.0$secondaryArchSuffix
	lib:libsnappy$secondaryArchSuffix
	lib:libssh2$secondaryArchSuffix
	lib:libtasn1$secondaryArchSuffix
	lib:libusb_1.0$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	devel:libbz2$secondaryArchSuffix
	devel:libcurl$secondaryArchSuffix
	devel:libfdt$secondaryArchSuffix
	#devel:libgcrypt$secondaryArchSuffix
	devel:libGL$secondaryArchSuffix
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgnutls$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:liblzo2$secondaryArchSuffix
	devel:libncursesw$secondaryArchSuffix
	devel:libnettle$secondaryArchSuffix
	devel:libpixman_1$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libsdl2_2.0$secondaryArchSuffix
	devel:libsnappy$secondaryArchSuffix
	devel:libssh2$secondaryArchSuffix
	devel:libtasn1$secondaryArchSuffix
	devel:libusb_1.0$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:awk
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:gcov$secondaryArchSuffix
	cmd:gprof$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:pod2man
	cmd:python
	"

BUILD()
{
	export CFLAGS="-lbsd -lnetwork"
	runConfigure --omit-buildspec ./configure \
		--disable-stack-protector \
		--target-list=i386-softmmu,x86_64-softmmu
		# remove the line above to get all the supported targets
		# aarch64-softmmu broken with --disable-stack-protector
	make $jobArgs
}

INSTALL()
{
	make install $jobArgs

	# provide convenience symlink to just "qemu"
	if [ $effectiveTargetArchitecture == x86_64 ]; then
		ln -s qemu-system-x86_64 $binDir/qemu
	else
		ln -s qemu-system-i386 $binDir/qemu
	fi
}
