# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Stefan Wagner <stw@bit-strickerei.de>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=notmuch
pkgver=0.38.3
pkgrel=1
pkgdesc="E-Mail index, search and tagging"
url="https://notmuchmail.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	bash
	bash-completion-dev
	emacs-nox
	gmime-dev
	gzip
	perl
	py3-gpep517
	py3-requests
	py3-setuptools
	py3-sphinx
	py3-wheel
	python3-dev
	talloc-dev
	xapian-core-dev
	"
checkdepends="
	coreutils
	dtach
	mandoc
	sed
	tar
	"
subpackages="
	py3-$pkgname-pyc
	py3-$pkgname:py3:noarch
	$pkgname-doc
	$pkgname-dev
	$pkgname-libs
	$pkgname-emacs:emacs:noarch
	$pkgname-vim:vim:noarch
	$pkgname-zsh-completion
	$pkgname-bash-completion"
source="https://notmuchmail.org/releases/notmuch-$pkgver.tar.xz
	test-musl-invalid-regexp.patch
	"

prepare() {
	default_prepare
	git init -q .
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--without-rpath \
		--bashcompletiondir=/usr/share/bash-completion/completions \
		--zshcompletiondir=/usr/share/zsh/site-functions
	make

	cd bindings/python
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	cd test
	make test-binaries

	local test
	for test in T*.sh; do
		name="$(basename "$test")"
		case "${name%%.*}" in
		# seems to have an extra Cc: and fail
		T220-reply) continue ;;
		# Requires dtach ↦ doesn't work on the builders
		*emacs*|T355-smime|T350-crypto) continue ;;

		# XXX: Doesn't pass on the builders for some reason
		T050-new|T140-excludes|T590-libconfig) continue ;;

		# FIXME fails on riscv64
		T620-lock) continue ;;

		# FIXME: These should pass but currently don't
		T150-tagging|T060-count|T070-insert|T357-index-decryption) continue ;;

		# Requires Python bindings installed
		T055-path-config) continue ;;
		esac

		./$test
	done
}

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

	cd bindings/python
	python3 -m installer -d "$pkgdir" .dist/*.whl

	make -C "$builddir"/vim DESTDIR="$pkgdir" \
		prefix="/usr/share/vim/vimfiles" install
}

vim() {
	depends="vim notmuch=$pkgver-r$pkgrel"
	pkgdesc="Vim plugins for $pkgname"

	amove usr/share/vim
}

emacs() {
	depends="emacs notmuch=$pkgver-r$pkgrel"
	pkgdesc="Emacs plugins for $pkgname"

	amove usr/share/emacs

	amove usr/bin/notmuch-emacs-mua
}

py3() {
	pkgdesc="$pkgdesc (for python3)"
	depends="py3-cffi"

	amove usr/lib/python3*
}

sha512sums="
247f8b365a75b29df719403bc2c9645eb669a7ee6eb4c1e0047dcf55fea4d66c8dcb4899162b952643aa6148ec6e1538ebe3e7e8408376153165e394084aed19  notmuch-0.38.3.tar.xz
0defaeb6781694d55f2e11a5ede37214d261bab4eed328d523cfda80deb11085a1486aa13e180cebc3b24dddfa073d17f7b9e2891c176d60aafa62509a28d55c  test-musl-invalid-regexp.patch
"
