# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           perl5                       1.0

name                notmuch
version             0.38.3
revision            0
checksums           rmd160  5dec7b4dc2db2c731ad106ab1f15c6b911fb4a40 \
                    sha256  9af46cc80da58b4301ca2baefcc25a40d112d0315507e632c0f3f0f08328d054 \
                    size    805416

categories          mail
license             GPL-3+
maintainers         nomaintainer
description         Fast, global-search and tag-based email system
long_description    \"Not much mail\" is what Notmuch thinks about your email \
                    collection, even if you receive 12000 messages per month or have on the \
                    order of millions of messages that you've been saving for decades. \
                    Regardless, Notmuch will be able to quickly search all of it. It's just \
                    plain not much mail.

homepage            https://notmuchmail.org
master_sites        ${homepage}/releases/
use_xz              yes

set python_branch   3.13
set python_version  [string map {. {}} ${python_branch}]

depends_build       port:bash-completion \
                    path:bin/doxygen:doxygen \
                    port:pkgconfig \
                    port:python${python_version} \
                    port:py${python_version}-cffi \
                    port:py${python_version}-sphinx \
                    port:py${python_version}-sphinxcontrib-applehelp \
                    port:py${python_version}-sphinxcontrib-devhelp \
                    port:py${python_version}-sphinxcontrib-htmlhelp \
                    port:py${python_version}-sphinxcontrib-jsmath \
                    port:py${python_version}-sphinxcontrib-qthelp \
                    port:py${python_version}-sphinxcontrib-serializinghtml \
                    port:texinfo

depends_lib         port:gmime3 \
                    port:gpgme \
                    port:talloc \
                    port:xapian-core \
                    port:zlib

configure.args      --with-docs \
                    --without-desktop \
                    --without-emacs \
                    --without-ruby

# Ensure headers are searched against the work area first, before those in
# ${prefix}/include. Fixes build failures caused by referencing the previous
# version's headers, during an update.
# https://nmbug.notmuchmail.org/nmweb/show/7851CAB5-4556-4931-A0A2-37003E56C927%40ryandesign.com
configure.cppflags-replace \
                    -I${prefix}/include \
                    -isystem${prefix}/include

# Undefined symbols: "__ZN6Xapian20sortable_unserialiseERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE"
compiler.cxx_standard \
                    2011

# Ensure libraries built in the work area are found first, before those in
# ${prefix}/lib. -L${prefix}/lib still gets added later in the build command
# by the build system to find MacPorts libraries.
# https://nmbug.notmuchmail.org/nmweb/show/7851CAB5-4556-4931-A0A2-37003E56C927%40ryandesign.com
configure.ldflags-delete \
                    -L${prefix}/lib

configure.python    ${prefix}/bin/python${python_branch}

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

# Add path to sphinx-build
configure.env-append \
                    PATH=${frameworks_dir}/Python.framework/Versions/${python_branch}/bin:$env(PATH) \
                    TMPDIR=/tmp
build.env-append    {*}${configure.env}
destroot.env-append {*}${configure.env}

# disable silent rules
build.args          V=1

variant emacs description {EMACS support} {
    depends_lib-append      port:emacs
    configure.args-delete   --without-emacs
    configure.args-append   --with-emacs
}

variant mutt description {Include Mutt integration} {
    depends_build-append    bin:pod2man:perl5
    depends_lib-append      port:perl5 \
                            port:p${perl5.major}-mailtools \
                            port:p${perl5.major}-mail-box \
                            port:p${perl5.major}-mail-message \
                            port:p${perl5.major}-term-readline-gnu \
                            port:p${perl5.major}-string-shellquote \
                            port:p${perl5.major}-mime-types \
                            port:p${perl5.major}-object-realize-later
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}

post-destroot {
    if {[variant_isset mutt]} {
        system -W ${worksrcpath}/contrib/notmuch-mutt "make DESTDIR=${destroot} prefix=${prefix} V=1 PERL_ABSOLUTE=${prefix}/bin/perl install"
    }
}
