# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           python 1.0

name                py-eric-ide
set real_name       eric6
version             21.4
revision            0

categories-append   devel
platforms           darwin
supported_archs     noarch
license             GPL-3+
maintainers         {reneeotten @reneeotten} openmaintainer

description         Eric is a full featured Python and Ruby editor and IDE
long_description    ${description}, written in python. It is based on the cross \
                    platform Qt gui toolkit, integrating the highly flexible \
                    Scintilla editor control. It is designed to be usable as \
                    everdays' quick and dirty editor as well as being usable \
                    as a professional project management tool integrating many \
                    advanced features Python offers the professional coder.

homepage            https://eric-ide.python-projects.org/index.html
master_sites        sourceforge:project/eric-ide/${real_name}/stable/${version}
distname            ${real_name}-${version}

checksums           rmd160  36e0ec5ca461b6805dad081c690580e9c969bf66 \
                    sha256  44335bf9a5e7f63fc833012a24ad2a299e5d42b9a45a1b580bca29209be63fab \
                    size    17420721

python.versions     27 37 38 39

if {${name} ne ${subport}} {
    if {${os.platform} eq "darwin" && ${os.major} <= 13} {
        default_variants +qt4
    } elseif {![ variant_isset qt4 ]} {
        default_variants +qt5
    }

    if {${python.version} eq 27 || [ variant_isset qt4 ]} {
        version         19.8
        revision        0
        # SourceForge directory name is YY.MM, with leading zero for month
        lassign         [split ${version} .] year month
        set directory   [format %i.%02i ${year} ${month}]
        master_sites    sourceforge:project/eric-ide/${real_name}/stable/${directory}
        distname        ${real_name}-${version}
        checksums       rmd160  34a8f2a9b2af2fa0e0e4b17e6822c97ed13ac864 \
                        sha256  7adcc5299df105d70eae71b4ed02781c937858ac2aee6bfc8dbf63f68527b025 \
                        size    17205953
        patchfiles      patch-install.py_v198.diff \
                        patch-disable-update-check_v198.diff
        livecheck.type  none
    } else {
        patchfiles      patch-install.py.diff \
                        patch-disable-update-check.diff
    }

    post-patch {
        reinplace "s|@@PYTHON_BIN_NAME@@|${python.bin}|g" ${worksrcpath}/install.py
        reinplace "s|@@PYTHON_PKG_DIR@@|${python.pkgd}/${real_name}|g" ${worksrcpath}/install.py
        if {[ variant_isset qt4 ]} {
            reinplace "s|@@PYQT_VERSION@@|--pyqt4|g" ${worksrcpath}/install.py
        } else {
            reinplace "s|@@PYQT_VERSION@@|--pyqt5|g" ${worksrcpath}/install.py
        }
    }

    variant qt5 conflicts qt4 description "Use Qt5 backend" {
        PortGroup   qt5 1.0

        qt5.min_version 5.12

        depends_lib-append  \
                    port:py${python.version}-pyqt5 \
                    port:py${python.version}-pyqt5-webengine \
                    port:py${python.version}-pyqt5-chart \
                    port:py${python.version}-qscintilla-qt5

        if {${python.version} eq 27} {
            depends_lib-delete  \
                    port:py${python.version}-pyqt5-chart \

            build.args-append --pyqt=5
        }
    }

    variant qt4 conflicts qt5 description "Use Qt4 backend" {
        PortGroup   qt4 1.0

        depends_lib-append \
                    port:py${python.version}-pyqt4 \
                    port:py${python.version}-qscintilla-qt4

        build.args-append --pyqt=4
    }

    depends_lib-append \
                    port:py${python.version}-cx_Freeze \
                    port:py${python.version}-enchant \
                    port:py${python.version}-pylint \
                    port:py${python.version}-pysvn \
                    port:py${python.version}-rope

    if {${python.version} >= 37} {
        depends_lib-append \
                    port:py${python.version}-yaml \
                    port:py${python.version}-toml
    }

    build.cmd       ${python.bin} install.py
    build.args      -b ${python.prefix}/bin \
                    -i ${destroot} \
                    -n ${destroot}${applications_dir} \
                    -m ${real_name}-${python.branch}.app \
                    --no-apis
    build.target

    destroot { }

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 {*}[glob ${worksrcpath}/eric/docs/*] \
            ${destroot}${docdir}
    }

    livecheck.type  none
} else {
    livecheck.regex ${real_name}-(\[0-9.\]+)${extract.suffix}
}
