# -*- 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               deprecated 1.0

deprecated.upstream_support no

name                    py27-pyqt5
python.rootname         PyQt5
categories-append       devel
maintainers             nomaintainer
description             PyQt5 is a set of Python bindings for the Qt5 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
license                 {GPL-3 OpenSSLException}

version                 5.15.4
revision                1
checksums               rmd160  c0f93412d4010e5e0d8e14e61af9579b66065bb4 \
                        sha256  2a69597e0dd11caabe75fae133feca66387819fc9bc050f547e5551bce97e5be \
                        size    3258085

python.versions         27
subport "${name}-common" {}

foreach py_ver ${python.versions} {
    subport "py${py_ver}-pyqt5-webengine" {}
    subport "py${py_ver}-pyqt5-chart" {}
}

if {${subport} eq "${name}-common"} {
    description-append          (.sip sourcefiles)
    long_description-append     This port contains the .sip source files.
    platforms                   any
    supported_archs             noarch
    depends_lib
    use_configure               no
    build                       {}
    destroot {
        xinstall -m 0755 -d ${destroot}${prefix}/share/sip/PyQt5
        # copy all relevant directories from ${worksrcpath}/sip into the destination.
        # This is exactly what the regular build system does, except that here we
        # use the same location as used on Linux, not the one hidden in the Python
        # framework that is apparently the default on Mac.
        file copy {*}[glob -directory ${worksrcpath}/sip/ Q*] ${destroot}${prefix}/share/sip/PyQt5
        file copy ${worksrcpath}/sip/Enginio ${destroot}${prefix}/share/sip/PyQt5
    }

} elseif {[string first "webengine" ${subport}] != -1 || [string first "chart" ${subport}] != -1} {
    PortGroup           qmake5 1.0

    compiler.cxx_standard 2011
    depends_lib-append  port:py${python.version}-pyqt5
    use_configure       yes
    configure.pre_args
    configure.cmd       "${python.bin} configure.py"
    qt5.spec_cmd        --spec=
    configure.args-append \
                        -q ${qt_qmake_cmd} \
                        --verbose \
                        --sip=${prefix}/bin/sip-${python.branch} \
                        --no-qsci-api \
                        --no-dist-info

    build.cmd           make
    build.target        all
    destroot.cmd        ${build.cmd}
    destroot.destdir    DESTDIR=${destroot}

    if {[string first "webengine" ${subport}] != -1} {
        python.rootname     PyQtWebEngine
        version             5.15.5
        revision            0
        description         PyQt5 Webengine bindings
        long_description    ${description}
        checksums           rmd160  de2dff392659b55265d4ef472d61ca75cceafda9 \
                            sha256  ab47608dccf2b5e4b950d5a3cc704b17711af035024d07a9b71ad29fc103b941 \
                            size    48610

        qt5.depends_component \
                            qtwebengine
    } elseif {[string first "chart" ${subport}] != -1} {
        python.rootname     PyQtChart
        version             5.15.4
        revision            0
        description         PyQt5 Charts bindings
        long_description    ${description}
        checksums           rmd160  d6177d643f23faeb557d17e0d6b77941d8d67a40 \
                            sha256  e47750632851e105eabc27fdfa8180989d120b822181e512f6643b3c5c4d8074 \
                            size    69252

        qt5.depends_component \
                            qtcharts
    }

} else {
    PortGroup           qmake5 1.0

    compiler.cxx_standard 2011
    # pull in the Qt5 meta-port
    qt5.depends_component \
                        qtscript \
                        qt3d \
                        qt5
    depends_lib-append  port:py${python.version}-sip4 \
                        port:dbus-python${python.version} \
                        port:py${python.version}-enum34

    use_configure       yes
    configure.pre_args
    configure.cmd       "${python.bin} configure.py"
    qt5.spec_cmd        --spec=
    configure.args-append \
                        -q ${qt_qmake_cmd} \
                        --verbose \
                        --confirm-license \
                        --sip=${prefix}/bin/sip-${python.branch} \
                        --dbus=${python.include}/dbus-1.0 \
                        --designer-plugindir=${qt_plugins_dir}/designer/Py${python.version}Qt5 \
                        --qml-plugindir=${qt_plugins_dir}/Py${python.version}Qt5 \
                        --no-qsci-api \
                        --disable=QtWebKit \
                        --disable=QtWebKitWidgets \
                        --no-dist-info \
                        --allow-sip-warnings

    # using --dbus means the compiler will find dbus-python.h but not
    # the DBus headers themselves
    # do not clear include directories just because --dbus is given
    patchfiles-append   patch-dbus_includes.diff
    # PyQt5 insists on using a private copy of sip, but the default sip seems to work just fine
    # (actually, the insistence appears to be on sip using a private module directory;
    # see the online pyqt5 build-from-source instructions).
    patchfiles-append   patch-use-default-sip.diff

    build.cmd           make
    build.target        all
    destroot.cmd        ${build.cmd}
    destroot.destdir    DESTDIR=${destroot}

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

    variant scintilla description {Build the PyQt API for QScintilla} {
        depends_lib-append      port:qscintilla-qt5
        configure.args-replace  --no-qsci-api \
                                --qsci-api

        post-destroot {
            # move the Qsci API file to a Python specific name
            # it is generated during the configure step and differs only
            # (and slightly) for python 2.x vs. python 3.x .
            # Figure out a way to install only a single copy...
            move ${destroot}${qt_data_dir}/qsci/api/python/PyQt5.api \
                ${destroot}${qt_data_dir}/qsci/api/python/PyQt5-Python${python.branch}.api
        }
    }

    variant webkit description {Build QtWebKit module} {
        qt5.depends_component   qtwebkit
        configure.args-delete   --disable=QtWebKit \
                                --disable=QtWebKitWidgets
    }

    variant graceful description {Don't abort (crash) on Python errors} {
        patchfiles-append       patch-no-abort-on-python-errors.diff
    }
}