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

# error: 'TARGET_OS_OSX' is not defined
legacysupport.newest_darwin_requires_legacy 14

name                libressl
version             4.0.0
revision            0
categories          security devel
license             OpenSSL SSLeay
maintainers         {@artkiver gmail.com:artkiver} {cal @neverpanic} openmaintainer

description         LibreSSL SSL/TLS cryptography library
long_description    LibreSSL is composed of four parts: \
                    The openssl(1) utility, which provides tools for managing keys, certificates, etc. \
                    libcrypto: a library of cryptography fundamentals \
                    libssl: a TLS library, backwards-compatible with OpenSSL \
                    libtls: a new TLS library, designed to make it easier to write foolproof applications \
                    This port tracks the stable releases, for development releases please use libressl-devel.
homepage            https://www.libressl.org

conflicts           openssl libressl-devel

master_sites        openbsd:LibreSSL
checksums           rmd160  9e6e05dcff145e666604903da7c66a4e642fc6cb \
                    sha256  4d841955f0acc3dfc71d0e3dd35f283af461222350e26843fea9731c0246a1e4 \
                    size    4259615

patchfiles          patch-openssldir-cert.pem.diff

configure.args \
    --disable-silent-rules \
    --with-openssldir=${prefix}/etc/ssl

post-patch {
    reinplace "s|@OPENSSLDIR@|${prefix}/etc/ssl|" ${worksrcpath}/include/openssl/opensslconf.h
}

# https://github.com/macports/macports-ports/pull/26250#issuecomment-2437709579
# https://trac.macports.org/ticket/69490
# LibreSSL 3.8 (and later in OpenSSL 3.4) implements new intrinsic code
# that increases compiler requirements. We can only use bootstrap Clang
# because the newer one depends on openssl and causes a dependency cycle.
if {${os.platform} eq "darwin" && ${os.major} < 18 && ${os.major} > 8} {
    if {${configure.build_arch} in {"x86_64" "i386"}} {
        depends_build-append port:clang-11-bootstrap
        depends_skip_archcheck-append clang-11-bootstrap
        configure.cc ${prefix}/libexec/clang-11-bootstrap/bin/clang
        configure.cxx ${prefix}/libexec/clang-11-bootstrap/bin/clang++
        # https://trac.macports.org/ticket/71201
        # https://trac.macports.org/ticket/71246
        # cctools is only needed for Snow Leopard i386/x86_64 and older.
        # On Yosemite and newer systems it triggers the dependency cycle again.
        if {${os.major} < 11} {
            depends_build-append port:cctools
        }
    }
}

# HOST_ASM_MACOSX_X86_64 gets set when building i386 on x86_64
set merger_configure_args(i386)     --disable-asm

platform darwin {
    if {${os.major} < 10} {
        configure.cppflags-append -DIPV6_TCLASS=36
    }
}

livecheck.type      regex
livecheck.url       https://www.libressl.org/
livecheck.regex     "The latest stable release is (\\d+\\.\\d+\\.\\d+)"