# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           boost 1.0
PortGroup           openssl 1.0

github.setup        trojan-gfw trojan 1.16.0 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            3
categories          net security
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             GPL-3

description         An unidentifiable mechanism that helps you bypass network restrictions.
long_description    Trojan features multiple protocols over TLS to avoid both \
                    active/passive detections and ISP QoS limitations. It doesn't rely on \
                    strong encryption or obfuscation\; instead it imitates the most \
                    common protocol, HTTPS, so firewalls won't see anything other than \
                    normal HTTPS traffic.

checksums           rmd160  0174f9e903a70fb1ed15244b62a2098b80c44abd \
                    sha256  b06b6133f7e43e559aae3a00c6e32f3a32738978497159e3a83c26c0af824246 \
                    size    51683

boost.version       1.81

# config.h:23:19: error: cstdint: No such file or directory
compiler.cxx_standard \
                    2011
# error: unknown type name 'max_align_t' on macOS <10.10
compiler.blacklist-append \
                    {clang < 700}

configure.args-append \
                    -DCMAKE_INSTALL_SYSCONFDIR=${prefix}/etc \
                    -DDEFAULT_CONFIG=${prefix}/etc/trojan/config.json \
                    -DENABLE_MYSQL=OFF

pre-configure {
    reinplace "s|/etc/trojan/config.json|${prefix}/etc/trojan/config.json|g" \
        ${worksrcpath}/docs/trojan.1
}

post-destroot {
    move ${destroot}${prefix}/etc/trojan/config.json ${destroot}${prefix}/etc/trojan/config.json.example
}

post-activate {
    if {![file exists ${prefix}/etc/trojan/config.json]} {
        copy ${prefix}/etc/trojan/config.json.example ${prefix}/etc/trojan/config.json
    }
}

notes-append "
    The default config file is copied to ${prefix}/etc/trojan/config.json and its content\
    will be preserved across upgrades and reinstalls. The startup item will use this config\
    file by default.
"

startupitem.create          yes
startupitem.executable      ${prefix}/bin/trojan --config=${prefix}/etc/trojan/config.json

proc dbvariants {dbport} {
    global prefix
    depends_lib-append \
                        port:${dbport}
    configure.args-replace \
                        -DENABLE_MYSQL=OFF -DENABLE_MYSQL=ON
    configure.args-append \
                        -DMYSQL_INCLUDE_DIR=${prefix}/include/${dbport}/mysql/ \
                        -DMYSQL_LIBRARIES=${prefix}/lib/${dbport}/mysql/
    configure.cppflags-append \
                        -I${prefix}/include/${dbport}/mysql
    configure.ldflags-append \
                        -L${prefix}/lib/${dbport}/mysql -lmysqlclient
}

variant mysql8 conflicts mysql81 mysql82 mariadb55 mariadb102 mariadb103 mariadb104 \
description {Enable authentication with a database using MySQL 8} {
    dbvariants "mysql8"
}

variant mysql81 conflicts mysql8 mysql82 mariadb55 mariadb102 mariadb103 mariadb104 \
description {Enable authentication with a database using MySQL 8} {
    dbvariants "mysql81"
}

variant mysql82 conflicts mysql8 mysql81 mariadb55 mariadb102 mariadb103 mariadb104 \
description {Enable authentication with a database using MySQL 8} {
    dbvariants "mysql82"
}

variant mariadb55 conflicts mysql8 mysql81 mysql82 mariadb102 mariadb103 mariadb104 \
description {Enable authentication with a database using MariaDB 5.5} {
    dbvariants "mariadb"
}

variant mariadb102 conflicts mysql8 mysql81 mysql82 mariadb55 mariadb103 mariadb104 \
description {Enable authentication with a database using MariaDB 10.2} {
    dbvariants "mariadb-10.2"
}

variant mariadb103 conflicts mysql8 mariadb55 mariadb102 mariadb104 \
description {Enable authentication with a database using MariaDB 10.3} {
    dbvariants "mariadb-10.3"
}

variant mariadb104 conflicts mysql8 mariadb55 mariadb102 mariadb103 \
description {Enable authentication with a database using MariaDB 10.4} {
    dbvariants "mariadb-10.4"
}
