TERMUX_PKG_HOMEPAGE="https://gitlab.com/accounts-sso/signon-plugin-oauth2"
TERMUX_PKG_DESCRIPTION="OAuth 2 plugin for signon"
TERMUX_PKG_LICENSE="LGPL-2.1-only"
TERMUX_PKG_LICENSE_FILE="COPYING"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="0.25"
TERMUX_PKG_SRCURL="https://gitlab.com/accounts-sso/signon-plugin-oauth2/-/archive/VERSION_${TERMUX_PKG_VERSION}/signon-plugin-oauth2-VERSION_${TERMUX_PKG_VERSION}.tar.gz"
TERMUX_PKG_SHA256="48a5bb61bf74fca458c870c1a27eedfe058b20f016c19a72aad2f5b151516447"
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_UPDATE_VERSION_REGEXP="VERSION_\d+.\d+"
TERMUX_PKG_UPDATE_VERSION_SED_REGEXP="s/VERSION_//"
TERMUX_PKG_DEPENDS="libc++, qt6-qtbase, signond"

termux_step_pre_configure() {
	export PKG_CONFIG_SYSROOT_DIR="$TERMUX__ROOTFS"
}

termux_step_configure() {
	pushd "${TERMUX_PKG_SRCDIR}"

	if [[ "$TERMUX_ON_DEVICE_BUILD" == "true" ]]; then
		qmake6 \
			PREFIX="$TERMUX__PREFIX" \
			CONFIG+=link_pkgconfig \
			CONFIG+=plugin \
			PKGCONFIG+=" signon-plugins" \
			INCLUDEPATH+="$TERMUX__PREFIX/include/signon-plugins" \
			INCLUDEPATH+="$TERMUX__PREFIX/include/signon-plugins/SignOn" \
			INCLUDEPATH+="$TERMUX__PREFIX/include/signon-qt6" \
			INCLUDEPATH+="$TERMUX__PREFIX/include/signon-qt6/SignOn"

		popd
		return
	fi
	# note: 'host-qmake6' appears to correctly set some necessary build settings,
	# such as '-Wl,-rpath,/data/data/com.termux/files/usr/lib'
	# and '-I/data/data/com.termux/files/usr/include/qt6/QtCore',
	# but fails to correctly set some other necessary build settings,
	# like 'aarch64-linux-android-clang++' and '-L/data/data/com.termux/files/usr/lib',
	# so this overrides only the settings that are absolutely necessary to correct,
	# while leaving other settings as they are.
	# also, it's unclear how to successfully pass more than one argument at a time in variables like CPPFLAGS
	# to variables like QMAKE_CXXFLAGS.
	"${TERMUX_PREFIX}/lib/qt6/bin/host-qmake6" \
		QMAKE_CXX="$CXX" \
		QMAKE_LINK="$CXX" \
		QMAKE_CXXFLAGS="-isystem$TERMUX__PREFIX__INCLUDE_DIR" \
		QMAKE_LFLAGS="-L$TERMUX__PREFIX__LIB_DIR" \
		PREFIX="$TERMUX__PREFIX"
	popd
}
