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

name                libbtbb
categories          devel net security
description         Bluetooth baseband decoding library.
long_description    Bluetooth baseband decoding library, forked from the GR-Bluetooth project. \
                    It can be used to extract Bluetooth packet and piconet information \
                    from Ubertooth devices as well as GR-Bluetooth/USRP.
license             GPL-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

subport             ${name}-devel {}

if {${subport} eq "${name}"} {
    conflicts       ${name}-devel

    github.setup    greatscottgadgets libbtbb 2020-12-R1
    revision        1
    checksums       rmd160  eca69c16710e4bf793cccfc722101e015a95b0e9 \
                    sha256  aa0588f21701156ccbd6b388fafe63225b41dd5b37b390f6c0ed3504d259847a \
                    size    308473
    github.tarball_from tarball
} elseif {${subport} eq "${name}-devel"} {
    conflicts       ${name}

    github.setup    greatscottgadgets libbtbb f0fe1768b080b1333a5357e8308d900e1273ec7f
    version         2022-08-26
    revision        1
    checksums       rmd160  82d6f97e4070ec7f14b64d3d21063c3b4d82fd9f \
                    sha256  daa64b8a746f87fb6a6f6e6c589ee251f98454d9b0093b665f883446b49d047f \
                    size    310865
    github.tarball_from tarball
}

patchfiles-append   patch-setup.py.in.diff patch-setup.py.diff

set python_ver      3.11
set py_ver_nodot    [string map {. {}} ${python_ver}]
depends_build-append \
                    port:py${py_ver_nodot}-setuptools
depends_lib-append  port:python${py_ver_nodot}

configure.python    ${prefix}/bin/python${python_ver}

configure.args-append \
                    -DPython3_EXECUTABLE=${configure.python}

set python_root     ${frameworks_dir}/Python.framework/Versions/${python_ver}/lib/python${python_ver}

post-patch {
    reinplace "s|/usr/bin/env python3|${configure.python}|" ${worksrcpath}/python/pcaptools/btaptap
    reinplace "s|/usr/bin/env python3|${configure.python}|" ${worksrcpath}/python/pcaptools/setup.py.in
    fs-traverse f ${worksrcpath}/python {
        if {[string match *.py ${f}]} {
            reinplace -q "s|/usr/bin/python|${configure.python}|" ${f}
            reinplace -q "s|/usr/bin/env python3|${configure.python}|" ${f}
        }
    }
}

# cc1: error: unrecognized command line option "-std=gnu90"
compiler.blacklist-append *gcc-4.*

platform darwin powerpc {
    # Needed for Rosetta
    compiler.blacklist-append clang
}

# This is not installed, but it is needed for btaptap executable to run:
post-destroot {
    xinstall -d ${destroot}${python_root}/site-packages
    copy ${cmake.build_dir}/python/pcaptools/build/lib/pcapdump ${destroot}${python_root}/site-packages/
}
