# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pinentry
pkgver=1.3.1
pkgrel=0
pkgdesc="Collection of simple PIN or passphrase entry dialogs which utilize the Assuan protocol"
url="https://www.gnupg.org/aegypten2/"
arch="all"
license="GPL-2.0-or-later"
install="
	$pkgname.post-install
	$pkgname.post-upgrade
	$pkgname-curses-ss.post-install
	$pkgname-curses-ss.post-deinstall
	"
makedepends="ncurses-dev libcap-dev libgpg-error-dev libassuan-dev libsecret-dev"
subpackages="$pkgname-doc $pkgname-tty $pkgname-curses-ss:_curses_ss"
source="https://gnupg.org/ftp/gcrypt/pinentry/pinentry-$pkgver.tar.bz2"

prepare() {
	default_prepare

	cp -ar "$builddir" "$builddir-libsecret"
}

build() {
	_build \
		--disable-libsecret \
		--enable-pinentry-curses \
		--enable-pinentry-tty

	cd "$builddir-libsecret"
	_build \
		--enable-libsecret \
		--enable-pinentry-curses \
		--disable-pinentry-tty
}

_build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-pinentry-gtk2 \
		--disable-pinentry-gnome3 \
		--disable-pinentry-qt \
		--enable-fallback-curses \
		"$@"
	make
}

check() {
	make check
}

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

	# created by post install scripts so we can override with other UI versions
	rm -f "$pkgdir"/usr/bin/pinentry
}

_curses_ss() {
	pkgdesc="Curses-based PIN or pass-phrase entry dialog for GnuPG with Secret Service support"

	install -D -m 755 "$builddir-libsecret"/curses/pinentry-curses \
		"$subpkgdir"/usr/bin/pinentry-curses-ss
}

tty() {
	pkgdesc="Minimal dumb-terminal PIN or pass-phrase entry dialog for GnuPG"

	amove usr/bin/pinentry-tty
}

sha512sums="
3b72034dc1792b1475acb6d605ff7c1bd7647a0f02d1b6bdcd475acdef24bc802f49e275055436c3271261c4b7a64168477a698aab812a145962146b2f67a0e2  pinentry-1.3.1.tar.bz2
"
