# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name    = "gnupg"
version = "2.4.9"

[source]
tarball = "https://gnupg.org/ftp/gcrypt/gnupg/gnupg-${pkgver/_beta/-beta}.tar.bz2"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "4638016b390a0024fa0cbe14181c43a81991e4275043855397ef099b927985d175d32452fc15b06485623b9292662dd6da464b2e5def8b77b2e4e48a072ab521"
sha256  = "FIXME-sha256"
patches = ["0001-include-unistd.patch", "0010-avoid-beta-warning.patch", "0020-avoid-regenerating-defsincdate-use-shipped-file.patch", "0110-avoid-simple-memory-dumps-via-ptrace.patch", "0210-dirmngr-hkp-avoid-potential-race-condition-when-some-host-die.patch", "0230-dirmngr-avoid-automatically-checking-upstream-swdb.patch", "0330-gpg-default-to-sha512-for-all-signature-types-on-rsa-keys.patch", "0340-gpg-prefer-sha512-and-sha384-in-personal-digest.patch", "0420-gpg-drop-import-clean-from-default-keyserver-import-options.patch", "fix-i18n.patch", "HACK-revert-rfc4880bis-default.patch"]

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

[build.phases]
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3; revisá --shared para estático):
compile = '''
_abuild_phase() {
./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-nls \
		--enable-bzip2 \
		--enable-tofu \
		--enable-scdaemon \
		--enable-ccid-driver
	make
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
make DESTDIR="/out" install

	install -Dm644 -t "/out"/usr/lib/udev/rules.d/ "$srcdir"/60-scdaemon.rules

	cd "/out"

	# install compat symlink
	ln -s gpg  usr/bin/gpg2
	ln -s gpgv usr/bin/gpgv2

	# Remove docs for systemd-user
	rm -rf usr/share/doc/gnupg/examples/systemd-user

	# Remove gpg scheme interpreter - an internal tool used in gpg tests
	rm -rf usr/bin/gpgscm
}
_abuild_phase
'''

[deps]
build = ["autoconf", "automake", "bzip2", "gettext", "gnutls", "libassuan", "libgcrypt", "libgpg-error", "libksba", "libtool", "libusb", "npth", "openldap", "pinentry", "sqlite", "texinfo", "xz", "zlib"]
