# Template file for 'tageditor'
pkgname=tageditor
version=3.7.8
revision=1
build_style=cmake
configure_args="-DBUILD_SHARED_LIBS:BOOL=ON"
hostmakedepends="pkg-config"
makedepends="tagparser-devel cpp-utilities-devel"
short_desc="Tag editor for AAC, ID3, Vorbis, Opus, FLAC and Matroska"
maintainer="Andrew J. Hesford <ajh@sideband.org>"
license="GPL-2.0-only"
homepage="https://github.com/Martchus/tageditor"
distfiles="https://github.com/Martchus/${pkgname}/archive/v${version}.tar.gz"
checksum=b7a4dda13c6e35fa6027b23efbecb975ff58d33d4c45cb23ba22b1a493a649b3

build_options="qt webengine webkit script"
build_options_default="qt"

desc_option_webengine="Enable support for qt5-webengine file views (requires qt)"
desc_option_webkit="Enable support for qt5-webkit file views (requires qt)"
desc_option_script="Enable support for qt5-script javascript (requires qt)"

case "$XBPS_TARGET_MACHINE" in
	x86_64*|aarch64*|armv[67]*|ppc64le*)
		if [ "$XBPS_WORDSIZE" = "$XBPS_TARGET_WORDSIZE" ]; then
			_use_webengine=yes
		fi
	;;
	*) ;;
esac

if [ "$_use_webengine" ]; then
	build_options_default+=" webengine"
else
	build_options_default+=" webkit"
fi

vopt_conflict webengine webkit

if [ "$build_option_qt" ]; then
	hostmakedepends+=" qt5-host-tools qt5-qmake"
	makedepends+=" qtutilities-devel qt5-tools-devel qt5-declarative-devel"

	if [ "$build_option_webengine" ]; then
		configure_args+=" -DWEBVIEW_PROVIDER=webengine"
		makedepends+=" qt5-location-devel
				qt5-webengine-devel qt5-webchannel-devel"
	elif [ "$build_option_webkit" ]; then
		configure_args+=" -DWEBVIEW_PROVIDER=webkit"
		makedepends+=" qt5-webkit-devel"
	else
		configure_args+=" -DWEBVIEW_PROVIDER=none"
	fi

	if [ "$build_option_script" ]; then
		configure_args+=" -DJS_PROVIDER=script"
		makedepends+=" qt5-script-devel"
	else
		configure_args+=" -DJS_PROVIDER=qml"
	fi
else
	configure_args+=" -DWIDGETS_GUI:BOOL=OFF -DQUICK_GUI:BOOL=OFF"
fi

pre_build() {
	if [ -z "$build_option_qt" ]; then
		vsed -i application/main.cpp -e "/^using namespace QtUtilities;$/s@^@//@"
	fi
}

post_install() {
	if [ -z "$build_option_qt" ]; then
		rm -rf "${DESTDIR}/usr/share/metainfo"
		rm -rf "${DESTDIR}/usr/share/icons"
		rm -rf "${DESTDIR}/usr/share/applications"
	fi
}
