# -*- 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           openssl 1.0

name                openssl
epoch               2
version             [openssl::default_branch]
revision            31

categories          devel security
license             MIT
maintainers         {larryv @larryv} {cal @neverpanic}

description         Shim port installing symbolic links in primary prefix pointing to \
                    the [openssl::depends_portname] installation.
long_description    {*}${description}
homepage            https://www.openssl.org/

conflicts           libressl libressl-devel
# This does not install architecture-specific files and would generate
# a warning because of that, but it still needs to stay architecture specific
# because otherwise +universal will not bubble through this when +universal
# ports only directly depend on this port, rather than openssl3.
test.ignore_archs   yes

distfiles
use_configure       no
build               {}

openssl::set_openssl_dependency
openssl.configure

# https://trac.macports.org/ticket/63616
compiler.cxx_standard

proc resolve_sym_link {fname} {
    set rc [catch {file readlink ${fname}} result]
    if { ${rc} eq 0 } {
        return ${result}
    } else {
        return ${fname}
    }
}

destroot {
    # Install symlinks from isolated libexec install area to primary ${prefix}
    ln -s [openssl::include_dir]/openssl  ${destroot}${prefix}/include/
    xinstall -d ${destroot}${prefix}/etc/openssl/
    foreach f [glob -tails -directory [openssl::install_area]/etc/openssl/ *] {
        # explicitly veto cert.pem as this is provided by curl-ca-bundle, and
        # in fact the file in opensslX is just a sym-link to it...
        if { ${f} ne "cert.pem" } {
            ln -s [openssl::install_area]/etc/openssl/${f} ${destroot}${prefix}/etc/openssl/
        }
    }
    ln -s [openssl::install_area]/share/doc/openssl ${destroot}${prefix}/share/doc/
    foreach man [glob -tails -directory [openssl::install_area]/share/man/ *] {
        foreach m [glob -nocomplain [openssl::install_area]/share/man/${man}/*] {
            ln -s ${m} ${destroot}${prefix}/share/man/${man}/
        }
    }
    foreach b [glob [openssl::bin_dir]/*] {
        ln -s ${b} ${destroot}/${prefix}/bin/
    }
    fs-traverse f [openssl::lib_dir] {
        set lf [string map "[openssl::install_area] ${prefix}" $f]
        if { [file isdirectory ${f}] } {
            xinstall -d ${destroot}${lf}
        } elseif { [file isfile ${f}] } {
            ln -s [resolve_sym_link ${f}] ${destroot}${lf}
        }
    }
}

universal_variant    yes

livecheck.type      none
