# -*- 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.4.1 v
name                cutter-rizin
revision            1
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  c92bcfa164dd52909222d04d76afa2944ab97861 \
                    sha256  7cafc3cac74aa3e69b14d9d790e7ea88ab856e37573000f7403289ec410867ef \
                    size    12303899

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

cmake.module_path   ${qt6.dir}/lib/cmake/Qt6LinguistTools

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 python39 conflicts python310 python311 python312 python313 python314 description {Enable Python support and bindings using Python 3.9} {
    set ::python_branch 3.9
    python-depends ${::python_branch}
}

variant python310 conflicts python39 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 python39 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 python39 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 python39 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 python39 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 python39] && ![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312]} {
    default_variants +python313
}
