# Maintainer: Integral <integral@member.fsf.org>

pkgname=qefientrymanager-git
_pkgname=${pkgname%-git}
_srcname=QEFIEntryManager
pkgver=0.5.0.r1.g91b137a
pkgrel=2
epoch=1
pkgdesc="A userspace cross-platform EFI boot entry management GUI App based on Qt"
arch=('x86_64' 'aarch64' 'riscv64')
url="https://github.com/Inokinoki/${_srcname}"
license=('GPL-3.0-or-later')
depends=('qt6-base' 'efivar' 'hicolor-icon-theme' 'polkit')
makedepends=('git' 'cmake' 'qt6-declarative' 'qt6-tools' 'clang')
conflicts=("${_pkgname}")
provides=("${_pkgname}")
source=(
	"git+${url}.git"
	"git+https://github.com/Inokinoki/qefivar.git"
)
sha256sums=('SKIP'
            'SKIP')

pkgver() {
	cd "${_srcname}/"
	git describe --long --tags --abbrev=7 | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//;s/_/./'
}

prepare() {
	cd "${_srcname}/"

	git submodule init
	git config submodule.qefivar.url "${srcdir}/qefivar/"
	git -c protocol.file.allow=always submodule update
}

build() {
	local cmake_options=(
		-B build
		-S "${_srcname}"
		-D CMAKE_BUILD_TYPE=None
		-D CMAKE_INSTALL_PREFIX=/usr
		-D CMAKE_INSTALL_MANDIR=/usr/share/man
		-D BUILD_CLI_UTILITY=ON
		-D USE_PKEXEC_LAUNCHER=ON
	)

	cmake "${cmake_options[@]}"
	cmake --build build
}

package() {
	DESTDIR="${pkgdir}" cmake --install build
	install -Dm644 "${_srcname}/README.md" -t "${pkgdir}/usr/share/doc/${_pkgname}/"
	rm "${pkgdir}/usr/bin/efibootmgr" # Avoid conflict with core/efibootmgr
}
