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

# Need strnlen() and strndup()
PortGroup               legacysupport 1.0
legacysupport.newest_darwin_requires_legacy 10

github.setup            VirusTotal yara 4.5.2 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
revision                0

categories              security
license                 GPL-2+
maintainers             nomaintainer

description             Malware identification and classification tool
long_description        YARA is a tool aimed at helping malware researchers to identify \
                        and classify malware samples.

checksums               rmd160  a0cc8c33a6cb1788eeee601479935901bac8bb88 \
                        sha256  0cf17edd08f74f88d0e48d9bf1481835e3061a441e539b8c785133552f9c663f \
                        size    2208466

if {${subport} eq ${name}} {
    depends_build-append \
                        port:autoconf \
                        port:automake \
                        port:libtool \
                        port:pkgconfig

    depends_lib-append  port:libmagic \
                        port:jansson \
                        path:lib/libssl.dylib:openssl \
                        port:pcre \
                        port:protobuf-c

    patchfiles          patch-configure.ac.diff \
                        patch-Makefile.am.diff

    pre-configure {
        system -W ${worksrcpath} "./bootstrap.sh"
    }

    # https://github.com/VirusTotal/yara/issues/1686
    configure.cflags-append -std=gnu99

    configure.args-append   --with-crypto \
                            --disable-silent-rules \
                            --disable-dependency-tracking \
                            --enable-cuckoo \
                            --enable-magic

    test.run            yes
    test.target         check

    github.livecheck.regex (\[0-9a-z.\]+)
}

set python.branches [list 3.8 3.9 3.10 3.11 3.12]

foreach b ${python.branches} {
    set python.branch          ${b}
    set python.version         [join [split ${python.branch} "."] ""]
    set python.bin             ${prefix}/bin/python${python.branch}
    set python.prefix          ${frameworks_dir}/Python.framework/Versions/${python.branch}

    subport py${python.version}-${name} {
        github.setup            VirusTotal yara-python 4.5.1 v
        # Change github.tarball_from to 'releases' or 'archive' next update
        github.tarball_from     tarball
        revision                0
        categories              security python
        description             ${name} bindings for python ${python.branch}
        long_description        Malware identification and classification tool. \
                                This subport provides bindings for python ${python.branch}

        checksums       rmd160  fc2ad545fe5c70cb8c81cde098269fa3621eb0a5 \
                        sha256  de5cb2d1d289e9d02d320add6cce0359cd5fda2830cf4939aeef066591215bc0 \
                        size    39436

        depends_build-append    port:py${python.version}-setuptools
        depends_lib-append      port:${name} \
                                port:python${python.version}

        use_configure           no

        build.cmd               ${python.bin} setup.py --no-user-cfg
        build.target            build --dynamic-linking

        destroot.cmd            ${python.bin} setup.py --no-user-cfg
        destroot.destdir        --prefix=${python.prefix} --root=${destroot}

        pre-test {
            test.env-append     PYTHONPATH=[glob -nocomplain ${worksrcpath}/build/lib*]
        }

        test.run                yes
        test.cmd                ${python.bin} tests.py
        test.target
    }
}