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

github.setup        rizinorg cutter 2.3.4 v
name                cutter-rizin
revision            2
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  d74bbc32f6f319117deb40627396f2960492cb83 \
                    sha256  edc266a5f7a1f1c7f71cf5c6c9727e05008b728eae3bb42beb7d0b24ce07c5c3 \
                    size    11608176

extract.rename      yes

depends_lib-append  port:rizin
depends_run-append  path:bin/dot:graphviz
qt5.depends_build_component \
                    qttools
#qt6.depends_build   qttools
qt5.depends_component \
                    qtsvg
#qt6.depends_lib     qtsvg

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
# Cannot build with Qt6 for now because we don't have pyside6 port

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_framework ${frameworks_dir}/Python.framework
        global python_framework
        # 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}-pyside2
        
        configure.args-append \
                            -DCUTTER_ENABLE_PYTHON=ON \
                            -DCUTTER_ENABLE_PYTHON_BINDINGS=ON \
                            -DPYTHON_LIBRARY="${python_framework}/Versions/${python_branch}/lib/libpython${python_branch}.dylib" \
                            -DPYTHON_INCLUDE_DIR="${python_framework}/Versions/${python_branch}/include/python${python_branch}" \
                            -DPYTHON_EXECUTABLE="${prefix}/bin/python${python_branch}"
}

# Python variants are currently broken due to https://trac.macports.org/ticket/65411
variant python39 conflicts python310 python311 description {Enable Python support and bindings using Python 3.9} {
    set ::python_branch 3.9
    # :: refers to global namespace, so the variable is created in global ns and is usable in pre-destroot
    python-depends ${::python_branch}
}

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

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

#if {![variant_isset python39] && ![variant_isset python310]} {
#    default_variants +python311
#}