# -*- 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           github 1.0
PortGroup           legacysupport 1.1

github.setup        neomutt neomutt 20240329
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1
categories          mail
license             GPL-2+
maintainers         {l2dy @l2dy} openmaintainer

description         The Mutt E-Mail Client (patched version with added features)
long_description    Mutt is a small but very powerful text-based MIME \
                    mail client. Mutt is highly configurable, and is \
                    well suited to the mail power user with advanced \
                    features like key bindings, keyboard macros, mail \
                    threading, regular expression searches and \
                    a powerful pattern matching language for selecting \
                    groups of messages.
homepage            https://neomutt.org

checksums           rmd160  b9721c5d480077d9a9a6b473a786d8393c2fb0da \
                    sha256  37a95ddb7463990c64386b4f4b8d34cdb8e1691d508d86192c2e64de611f7d90 \
                    size    3832735

depends_build-append \
                    path:bin/pkg-config:pkgconfig
depends_lib         path:bin/perl:perl5 \
                    path:lib/libssl.dylib:openssl \
                    port:gettext \
                    port:libiconv \
                    port:lz4 \
                    port:ncurses \
                    port:zlib \
                    port:zstd
depends_run         path:share/curl/curl-ca-bundle.crt:curl-ca-bundle

post-patch {
    # Use MacPorts Perl
    reinplace -W ${worksrcpath} "s|/usr/bin/perl|${prefix}/bin/perl|g" \
              docs/gen-map-doc

    reinplace -W ${worksrcpath} "s|/usr/bin/|${prefix}/bin/|g" \
              contrib/smime_keys \
              docs/manual.xml.head
    reinplace -W ${worksrcpath} "s|/usr/libexec/|${prefix}/libexec/|g" \
              docs/manual.xml.head
    reinplace -W ${worksrcpath} "s|/usr/local/|${prefix}/|g" \
              docs/manual.xml.head
    reinplace -W ${worksrcpath} "s|/usr/share|${prefix}/share|g" \
              docs/manual.xml.head
}

configure.args      --disable-doc \
                    --with-ncurses=${prefix} \
                    --with-nls=${prefix} \
                    --lz4 \
                    --with-ssl=${prefix} \
                    --with-zlib=${prefix} \
                    --zstd

# enriched.c: error: ‘for’ loop initial declaration used outside C99 mode
# Passing -std=c99 is not enough though:
# index/index.c: error: initializer element is not constant
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

# disable ccache, build issues with autosetup
configure.ccache     no
configure.env-append CCACHE=none CC_FOR_BUILD=${configure.cc}

default_variants    +doc +gpgme +idn +mutt
if {${install.user} ne "root"} {
    default_variants-append     +homespool
}

variant autocrypt requires gpgme sqlite description {Autocrypt support} {
    configure.args-append       --autocrypt
}
variant db4 conflicts db5 description {Enable header cache using Berkeley DB database} {
    configure.args-append       --with-bdb=${prefix} --with-bdb-version=4.8
    depends_lib-append          port:db48
}
variant db5 conflicts db4 description {Enable header cache using Berkeley DB database} {
    configure.args-append       --with-bdb=${prefix} --with-bdb-version=5.3
    depends_lib-append          port:db53
}
variant doc description {Build documentation} {
    configure.args-replace      --disable-doc --enable-doc
    depends_build-append        port:docbook-xml-4.2 port:docbook-xsl-nons port:libxslt port:w3m

    post-destroot {
        # install mime.types in ${prefix}/etc as previous versions used to do
        copy ${destroot}${prefix}/share/neomutt/mime.types \
             ${destroot}${prefix}/etc/mime.types.sample
    }
}
variant gdbm description {Enable header cache using GNU dbm database} {
    configure.args-append       --with-gdbm=${prefix}
    depends_lib-append          port:gdbm
}
variant gnutls description {Use GnuTLS} {
    configure.args-replace      --with-ssl=${prefix} --with-gnutls=${prefix}
    depends_lib-replace         path:lib/libssl.dylib:openssl path:lib/pkgconfig/gnutls.pc:gnutls
}
variant gpgme description {Enable GPGME crypto support} {
    configure.args-append       --gpgme
    depends_lib-append          port:gpgme
}
variant gss description {Support GSS API (Kerberos)} {
    configure.args-append       --with-gss=${prefix}
    depends_lib-append          port:kerberos5
}
variant homespool description {Spool mail in home directory (allows installing without root privileges)} {
    configure.args-append       --homespool
}
variant idn description {Internationalized Domain Name support} {
    configure.args-append       --with-idn2=${prefix}
    depends_lib-append          port:libidn2
}
variant kyotocabinet description {Enable header cache using Kyoto Cabinet database} {
    configure.args-append       --with-kyotocabinet=${prefix}
    depends_lib-append          port:kyotocabinet
}
variant lmdb description {Enable header cache using LMDB database} {
    configure.args-append       --with-lmdb=${prefix}
    depends_lib-append          port:lmdb
}
variant lua description {Lua scripting support} {
    configure.args-append       --with-lua=${prefix}
    depends_lib-append          port:lua
}
variant mutt description {Create 'mutt' symlink} {
    post-destroot {
        file link -symbolic ${destroot}${prefix}/bin/mutt neomutt
    }
}
variant notmuch description {Notmuch support} {
    configure.args-append       --with-notmuch=${prefix}
    depends_lib-append          port:notmuch
}
variant qdbm description {Enable header cache using QDBM database} {
    configure.args-append       --with-qdbm=${prefix}
    depends_lib-append          port:qdbm
}
variant rocksdb description {Enable header cache using RocksDB database} {
    configure.args-append       --with-rocksdb=${prefix}
    depends_lib-append          port:rocksdb
}
variant sasl description {Simple Authentication and Security Layer support} {
    configure.args-append       --with-sasl=${prefix}
    depends_lib-append          port:cyrus-sasl2
}
variant sqlite description {SQLite support} {
    configure.args-append       --with-sqlite=${prefix}
    depends_lib-append          port:sqlite3
}
variant tdb description {Enable header cache using Trivial database} {
    configure.args-append       --with-tdb=${prefix}
    depends_lib-append          port:tdb
}
variant tokyocabinet description {Enable header cache using Tokyo Cabinet database} {
    configure.args-append       --with-tokyocabinet=${prefix}
    depends_lib-append          port:tokyocabinet
}

post-destroot {
    move ${destroot}${prefix}/etc/neomuttrc \
         ${destroot}${prefix}/etc/neomuttrc.sample
}

post-activate {
    foreach f { mime.types neomuttrc } {
        if {![file exists ${prefix}/etc/${f}]} {
            copy ${prefix}/etc/${f}.sample \
                 ${prefix}/etc/${f}
        }
    }
}
