# Template file for 'mutt'
pkgname=mutt
version=1.5.24
revision=4
build_style=gnu-configure
configure_args="--enable-pop --enable-imap --enable-smtp --enable-hcache
 --enable-gpgme --with-regex --with-idn --with-ssl --with-sasl
 --with-gpgme-prefix=${XBPS_CROSS_BASE}/usr
 --with-gdbm=${XBPS_CROSS_BASE}/usr mutt_cv_regex_broken=no"
hostmakedepends="perl pkg-config libidn-devel"
makedepends="ncurses-devel libressl-devel libidn-devel gpgme-devel gdbm-devel
 libsasl-devel"
depends="mime-types"
conf_files="/etc/Muttrc"
short_desc="The Mutt Mail Client"
maintainer="Jan S. <jan.schreib@gmail.com>"
license="GPL-2"
homepage="http://www.mutt.org"
distfiles="http://ftp.mutt.org/pub/mutt/${pkgname}-${version}.tar.gz"
checksum=a292ca765ed7b19db4ac495938a3ef808a16193b7d623d65562bb8feb2b42200

build_options="trash sidebar"
desc_option_trash="Apply trash folder patch"
desc_option_sidebar="Apply sidebar patch"

if [ "$build_option_trash" ] || [ "$build_option_sidebar" ]; then
	hostmakedepends+=" automake"
fi
if [ "$build_option_trash" ]; then
	distfiles+=" http://ftp.cc.uoc.gr/mirrors/OpenBSD/distfiles/mutt/trashfolder-1.5.24.diff.gz"
	checksum+=" 395ffaa6517306e5f5e7327a1aacf3a5cadb34c5b6483170e3f314c95fdb5cb7"
fi
if [ "$build_option_sidebar" ]; then
	distfiles+=" http://lunar-linux.org/~tchan/mutt/patch-1.5.24.sidebar.20150917.txt"
	checksum+=" ddc2baeb4d882ac32b5c54965dfb3a9b3164b2387888be33f4c1d16ebbea5b98"
fi

if [ "$build_option_trash" ] || [ "$build_option_sidebar" ]; then
	pre_configure() {
		if [ "$build_option_trash" ]; then
			patch -sNp1 -i ${XBPS_BUILDDIR}/trashfolder-1.5.24.diff
			msg_normal "$pkgver: applied trashfolder patch.\n"
		fi
		if [ "$build_option_sidebar" ]; then
			patch -sNp1 -i ${XBPS_BUILDDIR}/patch-1.5.24.sidebar.20150917.txt
			msg_normal "$pkgver: applied sidebar patch.\n"
		fi
		autoreconf -fi
	}
fi

pre_build() {
	make CC="$BUILD_CC" CFLAGS="$BUILD_CFLAGS -fPIC" CPPFLAGS= mutt_md5
	make CC="$BUILD_CC" CFLAGS="$BUILD_CFLAGS -fPIC" CPPFLAGS= -C doc
}
post_install() {
	rm ${DESTDIR}/etc/Muttrc.dist
	rm ${DESTDIR}/etc/mime.types{,.dist}
	rm ${DESTDIR}/usr/bin/{flea,muttbug}
	rm ${DESTDIR}/usr/share/man/man1/{flea,muttbug}.1
	vinstall contrib/gpg.rc 644 etc Muttrc.gpg.dist
}
