# -*- 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.8.1
revision            0

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  180700441a8ffcb397872b5e1b92aa6d5c1f38ae \
                    sha256  91d937d6166274fafd70f4dee11a8da6dbfdb0da53de05f5d62361ddf775e256 \
                    size    1064723

python.versions     39 310 311 312 313
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 \
                    qtwebview \
                    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}

    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
    }
}