# -*- 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 on macOS <10.12
legacysupport.newest_darwin_requires_legacy 15

name                libressl-devel
version             4.1.0
revision            0
distname            libressl-${version}

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 development releases, for stable releases please use libressl.
homepage            https://www.libressl.org

conflicts           openssl libressl

master_sites        openbsd:LibreSSL
checksums           rmd160  5309b7e054cc472d6cf04430896186a79ed413ca \
                    sha256  0f71c16bd34bdaaccdcb96a5d94a4921bfb612ec6e0eba7a80d8854eefd8bb61 \
                    size    9198928

patchfiles \
    openssldir-cert.pem.patch

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 development release is (\\d+\\.\\d+\\.\\d+)"
