# Template file for 'notmuch'
pkgname=notmuch
version=0.38
revision=4
build_style=configure
build_helper=python3
configure_args="--prefix=/usr
 --emacslispdir=/usr/share/emacs/site-lisp/notmuch
 --emacsetcdir=/usr/share/emacs/site-lisp/notmuch"
hostmakedepends="perl pkg-config python3-Sphinx python3-devel texinfo
 desktop-file-utils emacs gnupg python3-setuptools python3-cffi"
makedepends="bash-completion gmime3-devel talloc-devel xapian-core-devel
 python3-cffi"
depends="gmime3>=3.2.7"
checkdepends="python3-pytest mdocml dtach gdb tar xz xapian-core
 openssl"
short_desc="Thread-based email index, search, and tagging"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-3.0-or-later"
homepage="https://notmuchmail.org"
distfiles="https://notmuchmail.org/releases/notmuch-${version}.tar.xz
 https://notmuchmail.org/releases/test-databases/database-v1.tar.xz"
checksum="a17901adbe43f481a6bf53c15a2a20268bc8dc7ad5ccf685a0d17c1456dbaf6e
 4299e051b10e1fa7b33ea2862790a09ebfe96859681804e5251e130f800e69d2"
skip_extraction="database-v1.tar.xz"
replaces="notmuch-emacs>=0"

# Not a real conflicts, but this package is broken with gpgme 1.13.1-
# gpgme is optional dependency
conflicts="gpgme<1.14.0_1"
subpackages="libnotmuch libnotmuch-devel notmuch-mutt
 notmuch-python3 python3-notmuch2"

if [ ! "$CROSS_BUILD" ]; then
	makedepends+=" ruby-devel"
	subpackages+=" notmuch-ruby"
fi

do_build() {
	make ${makejobs}
	make -C contrib/notmuch-mutt
	cd ${wrksrc}/bindings/python
	python3 setup.py build --build-base=build
	cd ${wrksrc}/bindings/python-cffi
	python3 setup.py build --build-base=build
}

do_check() {
	vsrccopy database-v1.tar.xz test/test-databases
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# Seem like gpgconf's problem,
		# mutt on musl also have problems with smime
		NOTMUCH_SKIP_TESTS="smime.3 smime.5"
	else
		# This test run under gdb is problematic
		NOTMUCH_SKIP_TESTS="count.14"
	fi
	# libconfig because of fqdn
	# we don't ship python-cffi
	NOTMUCH_SKIP_TESTS+=" libconfig python-cffi"
	NOTMUCH_SKIP_TESTS+=" crypto index-decryption"
	if [ $(id -u) = 0 ]; then
		NOTMUCH_SKIP_TESTS+=" new.36 new.39 tagging.25"
	fi
	export NOTMUCH_SKIP_TESTS
	make test
}

do_install() {
	make DESTDIR=${DESTDIR} install
	rm -f ${DESTDIR}/usr/share/applications/mimeinfo.cache
}

libnotmuch_package() {
	short_desc+=" - runtime library"
	pkg_install() {
		vmove usr/lib/*.so.*
	}
}

libnotmuch-devel_package() {
	short_desc+=" - development files"
	depends="libnotmuch-${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/*.so
	}
}

notmuch-mutt_package() {
	short_desc+=" - Mutt interface"
	depends="notmuch mutt perl-Mail-Box perl-MailTools
	 perl-String-ShellQuote perl-Term-ReadLine-Gnu perl-File-Which"
	pkg_install() {
		vbin contrib/notmuch-mutt/notmuch-mutt
		vman contrib/notmuch-mutt/notmuch-mutt.1
	}
}

notmuch-python3_package() {
	depends="libnotmuch python3"
	short_desc+=" - Python 3 bindings"
	pkg_install() {
		cd ${wrksrc}/bindings/python
		python3 setup.py build --build-base=build \
			install --prefix=/usr --root=${PKGDESTDIR}
	}
}

python3-notmuch2_package() {
	depends="libnotmuch python3"
	short_desc+=" - Python 3 cffi bindings"
	pkg_install() {
		cd ${wrksrc}/bindings/python-cffi
		python3 setup.py build --build-base=build \
			install --prefix=/usr --root=${PKGDESTDIR}
	}
}

notmuch-ruby_package() {
	short_desc+=" - Ruby bindings"
	pkg_install() {
		make DESTDIR=${PKGDESTDIR} -C bindings/ruby install
	}
}
