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

github.setup            psemiletov tea-qt 63.1.0
revision                0
checksums               rmd160  87acec8cf51a3a78b4cb8fd03a268ae61fdf782e \
                        sha256  15eba879907e31c1d2d061fae38fb5e43e1084689cbc057b5421cc3fb0a6a38d \
                        size    715890

name                    tea
description             TEA is the powerful text editor for GNU/Linux and *BSD.
maintainers             {ryandesign @ryandesign} openmaintainer
categories              editors
license                 GPL-3

long_description        {*}${description}

homepage                https://tea.ourproject.org
github.tarball_from     archive

depends_build-append    path:bin/pkg-config:pkgconfig

depends_lib-append      port:aspell \
                        port:hunspell \
                        port:zlib

patchfiles-append       tea-qmake.pro.patch

# Backport from upstream, drop on next update:
patchfiles-append       7126a9aef1f8313a2e97b7e3b1b8280f8f088935.patch

if {[string match *clang* ${configure.cxx}]} {
    configure.ldflags-append \
                        -stdlib=${configure.cxx_stdlib}
}

# https://github.com/psemiletov/tea-qt/issues/68
if {[string match *gcc* ${configure.compiler}]} {
    configure.cxxflags-append \
                        -fpermissive
}

# atypes.hxx: error: ‘nullptr’ was not declared in this scope
compiler.cxx_standard   2011

destroot {
    copy ${worksrcpath}/bin/tea.app ${destroot}${applications_dir}
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    # Somewhat arbitrary cutoff but motivated by the facts that Tea is known to
    # crash on startup at least on macOS 12 and 13 on x86_64 with Qt 4:
    # https://github.com/psemiletov/tea-qt/issues/64
    # and Qt 5 has dark mode support while Qt 4 does not.
    if {${os.platform} eq "darwin" && ${os.major} < 17} {
        default_variants-append +qt4
    } else {
        default_variants-append +qt5
    }
}

if {![variant_isset qt4] && ![variant_isset qt5]} {
    pre-fetch {
        ui_error "Either the qt4 or qt5 variant must be selected."
        return -code error "missing variant"
    }
}

variant qt4 conflicts qt5 description {Use Qt 4} {}
variant qt5 conflicts qt4 description {Use Qt 5} {}

if {[variant_isset qt4]} {
    PortGroup           qmake 1.0

}

if {[variant_isset qt5]} {
    PortGroup           qmake5 1.0

}
