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

github.setup        virtualsquare vde-2 2.3.3 v
name                vde2
revision            0
categories          net
maintainers         nomaintainer
license             GPL-2 LGPL-2.1 BSD-old

description         Virtual Distributed Ethernet

long_description    VDE is an ethernet compliant virtual network that can be \
                    spawned over a set of physical computer over the Internet.

github.tarball_from archive

checksums           rmd160  257d008bd8ce5a56f1ab7086a7f69a01f639294c \
                    sha256  a7d2cc4c3d0c0ffe6aff7eb0029212f2b098313029126dcd12dc542723972379 \
                    size    234790

conflicts           ${name}-devel

subport ${name}-devel {
    PortGroup       cmake 1.1

    github.setup    virtualsquare vde-2 6ad51c2fd557734011c140afc7b502d84cc5d3b0
    version         20260323-[string range ${github.version} 0 7]
    revision        0
    conflicts       ${name}

    checksums       rmd160  8a7d2823083e70408c9297b6870d3fde86c29585 \
                    sha256  81784c5618e9c7ec1e129a3b28d7a94d109671bbf85177aac4ce94d22594dd21 \
                    size    233059

    # Fix malformed Darwin linker flags in upstream's CMake build.
    patchfiles      patch-src-lib-CMakeLists.txt.diff
}

default_variants    +pcap

if {${subport} eq "${name}-devel"} {
    configure.args-append \
                    -DENABLE_EXPERIMENTAL=OFF \
                    -DENABLE_TUNTAP=OFF \
                    -DENABLE_PCAP=OFF \
                    -DENABLE_CRYPTCAB=OFF
} else {
    use_autoreconf  yes

    # The release uses old-style empty function prototypes that fail as C23.
    configure.cflags-append \
                    -std=gnu17

    configure.args  --disable-experimental \
                    --disable-tuntap \
                    --disable-pcap \
                    --disable-cryptcab
}

# See https://github.com/virtualsquare/vde-2/issues/6
use_parallel_build  no

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${subport}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} \
                    COPYING \
                    COPYING.libvdeplug \
                    Changelog \
                    README \
                    doc/README.UML \
                    doc/README.VirtualBox \
                    doc/README.bochs \
                    doc/README.qemu \
                    doc/README.slirpvde \
                    doc/README.vde_over_ns \
                    doc/freebsd_tap-HOWTO \
                    doc/vde_autolink-HOWTO \
                    doc/vdeqemu-HOWTO \
                    ${docdir}
}

variant tuntap description {Enable support for TAP devices} {
    depends_lib-append      port:tuntaposx
    if {${subport} eq "${name}-devel"} {
        configure.args-replace  -DENABLE_TUNTAP=OFF -DENABLE_TUNTAP=ON
    } else {
        configure.args-replace  --disable-tuntap --enable-tuntap
    }
}

variant pcap description {Enable support for packet capturing} {
    depends_lib-append      port:libpcap
    if {${subport} eq "${name}-devel"} {
        configure.args-replace  -DENABLE_PCAP=OFF -DENABLE_PCAP=ON
    } else {
        configure.args-replace  --disable-pcap --enable-pcap
    }
}

variant experimental description {Enable support for experimental features} {
    if {${subport} eq "${name}-devel"} {
        configure.args-replace  -DENABLE_EXPERIMENTAL=OFF -DENABLE_EXPERIMENTAL=ON
    } else {
        configure.args-replace  --disable-experimental --enable-experimental
    }
}
