# -*- 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                scamper
version             20251020
revision            0
categories          net
license             GPL-2
maintainers         {@matthewluckie luckie.org.nz:mjl} openmaintainer

description         Conduct Internet measurements
long_description    ${name} is a program that is able to conduct Internet \
                    measurement tasks to large numbers of IPv4 and IPv6 \
                    addresses, in parallel, to fill a specified \
                    packets-per-second rate. Currently, it supports the \
                    well-known ping and traceroute techniques, as well as \
                    radargun, ally, mercator, sting, and parts of tbit.

homepage            https://www.caida.org/catalog/software/scamper
master_sites        ${homepage}/code/

checksums           rmd160  c119ce069ffa898c0cc234083d422b09d8a5d238 \
                    sha256  6ef4d8d22c8cb3a4cc0391955d1a6c5f2c8e16f510c434f5cb9e9395676fcccd \
                    size    3291401

distname            ${name}-cvs-${version}

livecheck.regex     ${name}-cvs-(\[0-9\]+\[a-z\]*)${extract.suffix}

if {${subport} eq ${name}} {
    configure.args-append \
                    --enable-sc_hoiho \
                    --enable-sc_minrtt \
                    --enable-sc_uptime \
                    --with-pcre2

    depends_lib-append  path:lib/liblzma.dylib:xz \
                    path:lib/libbz2.dylib:bzip2 \
                    port:pcre2 \
                    port:sqlite3
}

# Python subports
set python_versions {39 310 311 312 313}
foreach v ${python_versions} {
    subport py${v}-${name} {
        PortGroup           python 1.0

        categories          net python

        depends_lib-append  port:${name}

        use_configure       yes

        python.default_version ${v}
        python.add_dependencies no
        build.cmd           make
        build.target
        destroot.cmd        make install
        destroot.destdir    DESTDIR=${destroot}

        livecheck.type      none
    }
}

# Python bindings for supported Python versions
if {[string match "py*" ${subport}]} {
    description             Python ${python.branch} bindings for scamper
    long_description        {*}${description}.

    depends_lib-append      port:python${python.version}

    configure.args-append   --with-python
    configure.env           PYTHON=${python.bin}
    configure.env-append    PYTHON_SITE_PKG=${python.pkgd}

    post-patch {
        reinplace "s|\$(scamper_la_DEPENDENCIES)||g" \
            ${worksrcpath}/lib/python/Makefile.in
        reinplace "s|../libscamperfile/libscamperfile.la|-lscamperfile|g" \
            ${worksrcpath}/lib/python/Makefile.in
        reinplace "s|../libscamperctrl/libscamperctrl.la|-lscamperctrl|g" \
            ${worksrcpath}/lib/python/Makefile.in
    }

    build.dir              ${worksrcpath}/lib/python
}
