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

github.setup        OpenVPN openvpn3 3.11.6 release/
github.tarball_from archive
revision            1
categories          net security
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             AGPL-3

description         easy-to-use, robust, and highly configurable VPN
long_description    \
    OpenVPN is an easy-to-use, robust, and highly configurable VPN (Virtual \
    Private Network) daemon which can be used to securely link two or more \
    private networks using an encrypted tunnel over the internet.

homepage            https://openvpn.net

checksums           rmd160  14bf32716b0d09ab9b555d7cc8d480d10550872b \
                    sha256  b53dcecb0931b517ab8f5045435aa4000c597b35fb129e4162e7b25ebc99f6cf \
                    size    2303656

depends_build-append \
                    port:asio \
                    port:jsoncpp \
                    port:xxhashlib
depends_lib-append  port:lz4 \
                    port:jsoncpp

compiler.cxx_standard \
                    2017

# error: 'filesystem' file not found
legacysupport.newest_darwin_requires_legacy \
                    18
legacysupport.use_mp_libcxx \
                    yes

# Disable building unit tests. See https://github.com/OpenVPN/openvpn3/issues/332
post-patch {
         reinplace "s|add_subdirectory(test/unittests)||g" ${worksrcpath}/CMakeLists.txt
}

variant openssl conflicts mbedtls openssl11 description "Use latest OpenSSL as the crypto library" {
    PortGroup           openssl 1.0
    configure.args-append \
                        -DOPENSSL_CRYPTO_LIBRARY=[openssl::lib_dir]/libcrypto.dylib \
                        -DOPENSSL_SSL_LIBRARY=[openssl::lib_dir]/libssl.dylib \
                        -DOPENSSL_INCLUDE_DIR=[openssl::include_dir]
}

variant openssl11 conflicts mbedtls openssl description "Use OpenSSL v1.1 as the crypto library" {
    PortGroup           openssl 1.0
    openssl.branch      1.1
    configure.args-append \
                        -DOPENSSL_CRYPTO_LIBRARY=[openssl::lib_dir]/libcrypto.dylib \
                        -DOPENSSL_SSL_LIBRARY=[openssl::lib_dir]/libssl.dylib \
                        -DOPENSSL_INCLUDE_DIR=[openssl::include_dir]
}

variant mbedtls conflicts openssl openssl11 description "Use mbedTLS as the crypto library" {
    configure.args-append \
                        -DUSE_MBEDTLS=ON
    depends_lib-append  port:mbedtls
}

variant nulltun description "Build an additional client binary with null tun" {
    configure.args-append -DCLI_NULLTUN=1
}

if {![variant_isset mbedtls] && ![variant_isset openssl11]} {
    default_variants +openssl
}
default_variants    +nulltun

destroot {
    xinstall -m 0755 {*}[glob ${cmake.build_dir}/test/ovpncli/ovpncli*] ${destroot}${prefix}/sbin
}

notes "
    OpenVPN 3 does not currently implement server functionality.
"
