# Maintainer: André Zwing <nerv@dawncrow.de>
pkgname=hangover-wine
pkgver=9.5
pkgrel=0
pkgdesc="Hangover runs simple Win32 applications on arm64 Linux"
url="https://github.com/AndreRH/hangover/"
# Wine already exist for x86_64 and x86, and Hangover is more advantageous on aarch64
arch="aarch64"
license="LGPL-2.0-or-later"
depends="
	libxi
	libxrandr
	"
depends_dev="$pkgname perl"
makedepends="
	alsa-lib-dev
	autoconf
	automake
	bison
	clang17
	cups-dev
	dbus-dev
	flex-dev
	fontconfig-dev
	freetype-dev
	gnutls-dev
	gstreamer-dev
	gst-plugins-base-dev
	krb5-dev
	libgphoto2-dev
	libpcap-dev
	libusb-dev
	libxcomposite-dev
	libxcursor-dev
	libxi-dev
	libxinerama-dev
	libxkbcommon-dev
	libxrandr-dev
	libxrender-dev
	lld
	llvm17
	mesa-dev
	ncurses-dev
	opencl-dev
	pcsc-lite-dev
	pulseaudio-dev
	sane-dev
	sdl2-dev
	udisks2-dev
	v4l-utils-dev
	vulkan-loader-dev
	wayland-dev
	"
subpackages="$pkgname-dev $pkgname-doc"
checkdepends="xvfb-run"
source="hangover-$pkgver.tar.gz::https://github.com/AndreRH/wine/archive/refs/tags/hangover-$pkgver.tar.gz
	rpath.patch
	"
builddir="$srcdir/wine-hangover-$pkgver"
options="textrels !check" # As of 2.0.3 most of the tests fails
# ignore tracing something in a weird rpath just to silence a warning
# no effect
somask="ntdll.so win32u.so"

prepare() {
	default_prepare
	# fix opencl header detection
	sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i configure*
}

build() {
	export CFLAGS="$CFLAGS -O2 -Wno-error=format-security"
	export CXXFLAGS="$CXXFLAGS -O2 -Wno-error=format-security"
	export CPPFLAGS="$CPPFLAGS -O2 -Wno-error=format-security"

	# invalid to the msys linker
	export LDFLAGS="${LDFLAGS/,-Wl,-z,pack-relative-relocs}"

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libdir=/usr/lib \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--with-dbus \
		--with-mingw \
		--with-x \
		--with-vulkan \
		--disable-box64cpu \
		--enable-archs=aarch64,i386 \
		"$(want_check || echo --disable-tests)"
	make
}

check() {
	xvfb-run make test
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 tools/wineapploader \
		"$pkgdir"/usr/bin/wineapploader

	local file
	for file in msiexec notepad regedit regsvr32 wineboot \
		winecfg wineconsole winefile winemine winepath; do
		rm -v "$pkgdir"/usr/bin/$file
		ln -sfv /usr/bin/wineapploader "$pkgdir"/usr/bin/$file
	done

	llvm-strip --strip-unneeded "$pkgdir"/usr/lib/wine/*-windows/*.dll
}

dev() {
	default_dev

	local file
	for file in widl wmc wrc winebuild winedump function_grep.pl \
		winedbg winemaker winegcc winecpp wineg++; do
		amove usr/bin/$file
	done
}

doc() {
	default_doc
	rm -fr "$subpkgdir"/usr/share/man/*.UTF-8
}
sha512sums="
4cef469a84d2fbf12ac85c3b4d7f7f531ebc48d7e07a5a9b5ce909582e37d34545c6ae969982da7188691443194d64077ec34159466cdee59c702aabf1d86f34  hangover-9.5.tar.gz
9881abfd0e7e4589cd5724291f9ec06ccb9d88b842c69abb5ea7865b6c27c778a060e60a9776c3620a030555cf61b8cceded55db9f04d5e45d9c627306763bff  rpath.patch
"
