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

# utimensat
legacysupport.newest_darwin_requires_legacy 16
legacysupport.redirect_bins nmail

github.setup        d99kris nmail 5.15.8 v
revision            0
categories          mail sysutils
license             MIT
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Terminal-based e-mail client
long_description    {*}${description} for macOS and Linux.
checksums           rmd160  ec7a02278d181015a403016a669c7a5e0880b1f8 \
                    sha256  51f763e310c5f4467a17a926a0e3b8b2eaeb166af888b3f0277c46b2961d56e8 \
                    size    1877274
github.tarball_from archive

# https://github.com/d99kris/nmail/issues/169
patchfiles-append   patch-remove-brewisms.diff
# Do not use bundled cereal and utfcpp.
# Also fix linking with openssl: https://github.com/d99kris/nmail/issues/194
patchfiles-append   patch-CMakeLists.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/CMakeLists.txt
}

depends_build-append \
                    port:cereal \
                    path:bin/pkg-config:pkgconfig \
                    port:utfcpp

depends_lib-append  port:curl \
                    port:cyrus-sasl2 \
                    port:expat \
                    port:libetpan \
                    port:libiconv \
                    port:libmagic \
                    port:ncurses \
                    port:ossp-uuid \
                    port:sqlite3 \
                    port:xapian-core \
                    port:zlib

compiler.cxx_standard   2017

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

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

depends_run-append  port:python${py_ver_nodot}

post-patch {
    reinplace "s|/usr/bin/env python3|${configure.python}|" \
        ${worksrcpath}/src/oauth2nmail
}

# Without pointing to uuid includes explicitly, the build picks a wrong header, despite finding the right library.
# CUSTOM_LIBETPAN stands for bundled libetpan, which we do not want.
configure.args-append \
                    -DHAS_CUSTOM_LIBETPAN=OFF \
                    -DHAS_STATIC_EXTLIBS=OFF \
                    -DLIBUUID_HEADERS=${prefix}/include/ossp
