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

github.setup        rizinorg cutter 2.5.0 v
name                ${github.project}-rizin
revision            0
github.tarball_from releases
distname            Cutter-v${version}-src

categories          devel aqua
license             GPL-3
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         Free and Open Source Reverse Engineering Platform powered by rizin
long_description    ${github.project} is a free and open-source reverse engineering platform powered by rizin. It aims at being an advanced and customizable\
                    reverse engineering platform while keeping the user experience in mind. Cutter is created by reverse engineers for reverse engineers.

homepage            https://cutter.re

checksums           rmd160  f8ba319b3c3757c1609dfa7e275f0419c0770597 \
                    sha256  b524208f2b09fa5edb6720db007f2f8013089d64bebd87aabd147f79bf5f40b9 \
                    size    14310870

depends_build-append \
                    port:pkgconfig
depends_lib-append  port:rizin \
                    port:graphviz

qt6.depends_build   qttools

qt6.depends_lib     qtsvg \
                    qt5compat

extract.rename      yes

compiler.cxx_standard \
                    2017

configure.args-append \
                    -DCUTTER_USE_BUNDLED_RIZIN=NO \
                    -DCUTTER_ENABLE_GRAPHVIZ=YES \
                    -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=NO \
                    -DCUTTER_EXTRA_PLUGIN_DIRS=${prefix}/lib/rizin/plugins \
                    -DCUTTER_QT6=ON

app.name            Cutter
app.identifier      re.[string trimright ${github.author} "org"].${github.project}
app.executable      ${prefix}/bin/${github.project}
app.icon            ${worksrcpath}/dist/macos/cutter.icns

post-destroot {
    file mkdir ${destroot}${prefix}/lib/rizin/plugins
}
destroot.keepdirs   ${destroot}${prefix}/lib/rizin/plugins

proc python-depends {python_branch} {
        global frameworks_dir prefix
        set python_version  [string map {. ""} ${python_branch}]
        set ::python_prefix ${frameworks_dir}/Python.framework/Versions/${python_branch}
        global python_prefix
        set ::python_pkgd   ${python_prefix}/lib/python${python_branch}/site-packages
        global python_pkgd
        # same here, and creating an alias of the variable in proc namespace so we can use it here

        depends_lib-append  port:python${python_version} \
                            port:py${python_version}-pyside6

        configure.args-append \
                            -DCUTTER_ENABLE_PYTHON=ON \
                            -DCUTTER_ENABLE_PYTHON_BINDINGS=ON \
                            -DPYTHON_LIBRARY="${python_prefix}/lib/libpython${python_branch}.dylib" \
                            -DPYTHON_INCLUDE_DIR="${python_prefix}/include/python${python_branch}" \
                            -DPYTHON_EXECUTABLE="${prefix}/bin/python${python_branch}"

        cmake.install_rpath-append \
                            ${python_pkgd}/PySide6 \
                            ${python_pkgd}/shiboken6
}

# :: refers to global namespace, so the variable is created in global ns and is usable in pre-destroot
variant python310 conflicts python311 python312 python313 python314 description {Enable Python support and bindings using Python 3.10} {
    set ::python_branch 3.10
    python-depends ${::python_branch}
}

variant python311 conflicts python310 python312 python313 python314 description {Enable Python support and bindings using Python 3.11} {
    set ::python_branch 3.11
    python-depends ${::python_branch}
}

variant python312 conflicts python310 python311 python313 python314 description {Enable Python support and bindings using Python 3.12} {
    set ::python_branch 3.12
    python-depends ${::python_branch}
}

variant python313 conflicts python310 python311 python312 python314 description {Enable Python support and bindings using Python 3.13} {
    set ::python_branch 3.13
    python-depends ${::python_branch}
}

variant python314 conflicts python310 python311 python312 python313 description {Enable Python support and bindings using Python 3.14} {
    set ::python_branch 3.14
    python-depends ${::python_branch}
}

if {![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312] && ![variant_isset python314]} {
    default_variants +python314
}

github.livecheck.regex  {([0-9.]+)}
