# -*- 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           python 1.0
PortGroup           qt6 1.0

name                py-pyqt6
python.rootname     PyQt6
version             6.11.0
revision            1

categories-append   devel
license             {GPL-3 OpenSSLException}
maintainers         {reneeotten @reneeotten} openmaintainer

description         PyQt6 is a set of Python bindings for the Qt6 toolkit
long_description    {*}${description}. The bindings are implemented as a set of \
                    Python modules and contain over 620 classes.

homepage            https://www.riverbankcomputing.com/software/pyqt/intro

distname            pyqt6-${version}

checksums           rmd160  a3e9535378a125dff320d5e6a2735899105f6bce \
                    sha256  45dd60aa69976de1918b5ced6b4e7b6a25abd2a919ecef5fd5826ecc76718889 \
                    size    1087430

python.versions     310 311 312 313 314
python.pep517       no

compiler.cxx_standard 2011

if {${name} ne ${subport}} {
    # fix permissions
    post-extract {
        fs-traverse item ${worksrcpath} {
            if {[file isdirectory ${item}]} {
                file attributes ${item} -permissions a+rx
            } elseif {[file isfile ${item}]} {
                file attributes ${item} -permissions a+r
            }
        }
    }

    patchfiles-append patch-project.py.diff

    post-patch {
        reinplace "s|@PYVER@|${python.version}|g" ${worksrcpath}/project.py
    }

    qt6.depends_lib qtpositioning \
                    qtquick3d \
                    qtquicktimeline \
                    qtdeclarative \
                    qtserialport \
                    qtsensors \
                    qtdoc \
                    qthttpserver \
                    qtwebchannel \
                    qtimageformats \
                    qtshadertools \
                    qtvirtualkeyboard \
                    qtsvg \
                    qt5compat \
                    qtlottie \
                    qtserialbus \
                    qtlanguageserver \
                    qtmultimedia \
                    qtremoteobjects \
                    qtquick3dphysics \
                    qtscxml \
                    qtconnectivity \
                    qtspeech \
                    qttools \
                    qtwebsockets \
                    qttranslations

    # list modules here that are only supported for newer Qt6 versions
    if {[vercmp ${qt6.version} 6.5] >= 0} {
        qt6.depends_lib-append \
                    qtlocation \
                    qtquickeffectmaker \
    }
    if {[vercmp ${qt6.version} 6.6] >= 0} {
        qt6.depends_lib-append \
                    qtgraphs
    }

    depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    port:py${python.version}-pyqt-builder \
                    path:${python.prefix}/bin/sip-build:py${python.version}-sip

    depends_lib-append \
                    port:dbus-python${python.version} \
                    port:dbus

    depends_run-append \
                    port:py${python.version}-pyqt6-sip

    build.args-append \
                    --qmake ${prefix}/libexec/qt6/bin/qmake \
                    --verbose \
                    --confirm-license \
                    --dbus=${python.include}/dbus-1.0 \

    build.cmd       sip-build-${python.branch}
    build.target

    pre-destroot {
        reinplace "s|sip-distinfo|sip-distinfo-${python.branch}|g" \
            ${build.dir}/build/Makefile
    }

    destroot.cmd    make
    destroot.dir    ${build.dir}/build
    destroot.target install
    destroot.destdir "INSTALL_ROOT=${destroot}"

    variant debug description "Build debug libraries" {
        build.cmd-append    --debug
    }
}
